aspose file tools*
The moose likes Servlets and the fly likes lost session attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "lost session attributes" Watch "lost session attributes" New topic
Author

lost session attributes

Matt Badowski
Greenhorn

Joined: Jan 18, 2008
Posts: 1
maybe i don't understand attributes, but here is my question/problem:

GuestJsp.java


logintest.jsp


so if i point straight to GuestJsp, it goes to logintest.jsp and brings up "attribute test" where it should. however, when you click the again link it reloads the same page but at the direct url for the page and brings up null. the attribute gets lost somewhere. so are attributes that are set in a servlet only valid while in the servlet url?
Lukasz Bajzel
Greenhorn

Joined: Dec 03, 2007
Posts: 26
request.setAttribute() sets the value in the current request. When you use RequestDispatcher and forward(), the same request is forwarded to the jsp and you get access to the value set in the attribute.

Now when you click the link, the request gets redirected to the page. So it is another request at this time and the original request and any values associated with it are gone at this point. Clickiing the link never goes to the Servlet again, it is directly redirected to the page by the web server.


Hope this helps!

Sincerly,
Your friends at www.javaadvice.com
www.javaadvice.com - The one stop resource for all your Java questions and answers.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

Your subject indicates that you expect the scoped variables (the correct term for attributes placed onto a scope) to be in the session, yet you are placing them in request scope. If you want the scoped variables to survive across multiple requests, you must place them in session scope.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: lost session attributes