Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Getting results to the forwarded page

 
Bartender
Posts: 1840
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my Struts Action, I get a returned List from a DB call.

In the action path entry in struts-config.xml, I have a "forward name = "
entry for the JSP that I want to go to to display the actual data.

My question is how do I set the "result" (List) into the session, (appropriate) form bean, etc., so the target JSP can access and then display the data? Currently, the target JSP (in the "forward name=") comes up, but there is no data.

I tried using the form bean from the first page (where the user selects the value that will be used for the DB call), but that didn't work.

Thanks in advance for help with this newbie question.



Mike
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your execute method, set the list to be a request attribute:


You will be able to access the attribute in your JSP:

[ January 15, 2008: Message edited by: Joe Ess ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing with Struts that can be a little confusing (and might be seen as a limitation) is that your action has just one form. That is often not a problem and you can configure the action that displays a page to use the same form as the action that processes the page's submission. In this case it is straight forward to populate data on the form in your display action.

In some cases the two actions deal with different forms. You could just stick values directly on the request, but I try to pass data using forms. In this case you just need to instantiate an instance of your form class, populate it with data, and then save the form as an attribute on the request. The name that you use just needs to match up with the "name" attribute of the process action (the action you specify in the html:form tag).

- Brent
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try using the second Action Form, populate them in the action. You need to put the Action Form in request / session scope. Then forward the request from the Action to the jsp which has the Action Form.
When displaying the Forwarded jsp, it will check whether the Action Form exists in scope, if it does it will populate else will display default values.
reply
    Bookmark Topic Watch Topic
  • New Topic