Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lost session attributes

 
Matt Badowski
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic