File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Request Object Lost During ActionForward to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Request Object Lost During ActionForward to JSP" Watch "Request Object Lost During ActionForward to JSP" New topic

Request Object Lost During ActionForward to JSP

Elle Atechsy
Ranch Hand

Joined: Jan 23, 2004
Posts: 96

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

1st step:

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

3rd step:

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"/>


Any help is greatly appreciated.

Vicky Pandya
Ranch Hand

Joined: Dec 16, 2004
Posts: 148

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

Joined: Jan 23, 2004
Posts: 96
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.

Thomas Mcfarrow
Ranch Hand

Joined: Jul 09, 2001
Posts: 137

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.


[ May 02, 2005: Message edited by: Thomas Mcfarrow ]
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
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.
Elle Atechsy
Ranch Hand

Joined: Jan 23, 2004
Posts: 96
Thanks, Thomas. It does work. I thought I tried that, but maybe I forgot to restart the server.

Thanks again!!!
I agree. Here's the link:
subject: Request Object Lost During ActionForward to JSP
jQuery in Action, 3rd edition