Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Losing object put into request scope after forward

 
Mike London
Ranch Hand
Posts: 1192
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1192
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic