• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Retrieving information from previous page's form

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

reply
    Bookmark Topic Watch Topic
  • New Topic