• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Losing object put into request scope after forward

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic