• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

lost session attributes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic