• 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

Request Object Lost During ActionForward to JSP

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Would anyone happen to know why I am losing my request object value between forwarding from the ActionClass to my JSP?

1st step:
Call jsppage.do

2nd step: In action...
go to DB
request.setAttribute("myObjName", obj);
forward.findForward("success");

3rd step:
request.getAttribute("myObjName");

but it is null.

I have tested even with only a string value, and still it does the same. Could this be a config problem?

If so, my action mapping looks like this:

<action name="siteMgmtFormBean" path="/cma/siteManagement/oosCMAoverviewEntry" scope="request" type="classPackageName" validate="false">

<forward name="success" redirect="true" path="/cma/siteManagement/oosCMAoverviewEntry.jsp"/>

<forward name="failure" path="/cma/siteManagement/oosCMAoverviewEntry.jsp"/>

</action>


Any help is greatly appreciated.

Thanks,
Lulu
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lulu,

You need to write request.getSession().setAttribute("myObjName", obj);

and while retrieving request.getSession().getAttribute("myObjName"); Make a not of getSession(). I am sure this will work and you find out why
 
Elle Atechsy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much, Vicky!! It works.

However, I'm a newbie at Struts and Java/JSP as well, so I don't quite understand what you mean by "Make a not of getSession()". I did read in the JavaDocs that the getSession() method of the HttpSession class gets a session that is associated with a request or creates one. But I still don't understand why i had to get my value that way. Because I had also tried a session.setAttribute("myobjname", obj) & it still did not work.

Would you mind explaining why what I had did not work, and the one you gave did?

Much appreciation.

Lulu
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

request.getSession().setAttribute(....) saves the values in session scope (HttpSession) which means the values will persist for the life of the user's session.

You are using the correct calls to set a value in the request scope. If that wasn't working I would check the struts-config.xml and make sure the redirect attribute from the forward node isn't set to "true". A redirect will dispose of all request attributes and parameters.

Request scope will persist for only the life of the request.

example:


[ May 02, 2005: Message edited by: Thomas Mcfarrow ]
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am little bit curious about did you tried whatever Thomas Mcfarrow told. Since I know you don't want to store object for session span you can use request object instead.If you tried his suggestion pls let me know.
Thanks
 
Elle Atechsy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Thomas. It does work. I thought I tried that, but maybe I forgot to restart the server.

Thanks again!!!
 
I AM MIGHTY! Especially when I hold this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic