File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "lost session attributes" Watch "lost session attributes" New topic

lost session attributes

Matt Badowski

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


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

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!

Your friends at - The one stop resource for all your Java questions and answers.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63857

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] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: lost session attributes
It's not a secret anymore!