File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Retrieving information from previous page's form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retrieving information from previous page Watch "Retrieving information from previous page New topic
Author

Retrieving information from previous page's form

Nicolás Muñoz
Greenhorn

Joined: Nov 11, 2009
Posts: 17
Hi. I'm new at Struts and I barely can use it. I have a page which has a form. This form is submitted to an Action Controller which checks some things and then sends the user to another page. My question is: how can I retrieve what the user put in the form in this last page? The Action Controller returns an ActionForward object. I'm assuming that this object has to have this information (not by default but one could put it there), but I'm not sure and, as I said, I practically know nothing about Struts. Thanks!
a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
Hi Nicolás,

Welcome to CodeRanch!!

how can I retrieve what the user put in the form in this last page?


What ever you enter in your first page, if its a jsp page, you can retrieve in your actionclass using request.getparameter().
In your action class you can do string validations.

The Action Controller returns an ActionForward object.

ActionForward object is to forward your action to a new jsp page or to a new action class.


-HTH

regards,
kishore
Nicolás Muñoz
Greenhorn

Joined: Nov 11, 2009
Posts: 17
Hi, kishore. If I understood you correctly, request.getParameter() can help me, but if I am in the .jsp page, I can't do this because I don't have the variable request. This variable is in a method of the Action Controller and I cannot call it from the .jsp page. Well, probably I'm wrong. I'm sorry for my lack of knowledge. I just don't know how to call a method from the Action Controller within .jsp
a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
Nicolás ,

how to call a method from the Action Controller within .jsp


I didnot get you properly, but then im posting some sample jsp and action class codes below. please go through it and comeback to me.

you can use this in your jsp:



for action class:




-HTH

regards,
kishore
Nicolás Muñoz
Greenhorn

Joined: Nov 11, 2009
Posts: 17
I understand what you're explaining to me. I did this. And it works. The doubt I have is the following: let's suppose I have 1.jsp and 2.jsp. In 1.jsp I have a form, and let's assume its code is what you posted here. When the user submits its username and password, then the LoginAction Controller must do some things but ultimately will return this:

as you said. In the configuration file of struts, it will look for "success" and because "success" it's related to an URL, it will send the user from 1.jsp to 2.jsp (it could be anywhere anyway). All of this I have done, but my question is: In 2.jsp how can I retrieve the username and password the user put in the form included in 1.jsp? I have been unable to do this. Thanks for all the help
a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
You have to set username and password in ActionForm and can retrieve in 2.jsp

to set into actionform, you can use the following code.



then in struts-config, you have to map this actionform like this



and in 2.jsp you can use this:



-HTH

regards,
kishore

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving information from previous page's form
 
Similar Threads
Problem when the struts validator rejects user input
Printing information based on a query from a user
"STRUTS-like action"
Multiple forms in Struts
Populate Backing Bean Exception Handling