aspose file tools*
The moose likes Struts and the fly likes Getting results to the forwarded page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting results to the forwarded page" Watch "Getting results to the forwarded page" New topic
Author

Getting results to the forwarded page

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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

Joined: Oct 29, 2001
Posts: 8710
    
    6

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 ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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

Joined: Feb 16, 2005
Posts: 18
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting results to the forwarded page
 
Similar Threads
Struts and Validator
Problem in setting a value of drop down
ActionForm question (struts 1)
Username existence check using AJAX and Java J2EE
JSP to Bean to Servlet