This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Losing object put into request scope after forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Losing object put into request scope after forward" Watch "Losing object put into request scope after forward" New topic
Author

Losing object put into request scope after forward

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
I have some code where I put an application object (app) into request scope and then look up a forward like this...

request.setAttribute("app", app);
result = mapping.findForward(viewErr.view);
return result;

However, when this method returns, app is not found in request scope at all (though it still is before the method returns 'result' above) -- it's lost.

Thus, since the variable app is not in request scope, the app crashes saying that the variable app was not found in request scope.

Is there something obvious I'm missing here with Struts forwards or other issues?

Thanks in advance!!!

-- Mike
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Mike,

This is most likely caused by specifying redirect="true" when you defined the forward. This causes anything put in the request to be lost. Jusr remove this attribute from your <forward> definition in the struts-config.xml file, and it should work fine.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
Thanks for your reply.

The redirect=true was only specified for the "success" action, not the "failure" action where this problem is occuring.

As in...

<action>
.
.
.
<forward
name="failure"
path="/WEB-INF/Test.jsp"/>
</action>

Am I misunderstanding what you were saying?

Look forward to your follow up.

Thanks for any and all input!!!

-- Mike
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The only other thing I can think of is that you may be doing something wrong when trying to access the bean through the Struts tags.

Try outputting the value with a scriptlet to make sure it really isn't there:

<% out.println(request.getAttribute("app").toString()); %>

If it really isn't there, show us the relevant portions of your struts-config.xml file, your JSP, and your Action class, and we'll try to help you figure out why it's not there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Losing object put into request scope after forward
 
Similar Threads
JSP/Servlet combination
problem regarding JSTL remove tag
Pass a variable from JSP to Servlet Action
Choosing Between Forward and Redirect
jsp can't get object from servlet using "getAttribute"