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

Request Object Lost During ActionForward to JSP

 
Elle Atechsy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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
 
Vicky Pandya
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Thomas Mcfarrow
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • 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 ]
 
anupa oru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • 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
  • 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!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic