This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting results to the forwarded page

 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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 ]
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • 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
 
Nadda Habba
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic