• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session does not persist

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a servlet that calls other classes and passes the request and response objects to them in a hashtable. Everyting works fine but when i call my login class from my command processor servlet the login class stored the users access level in the session with the following code:
HttpSession session = req.getSession(true);
session.setAttribute("access", accessLevel);
Later on one of my other servlet i try and access the accesslevel but it only returns null. what can it be?
the code in the class that want to access the session is as follows: HttpSession session = req.getSession(false);
String access = (String) session.getAttribute("access");
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you getting the session in your servlet? Beware that you can get a session in two ways, one which always creates a new session, and one which will get an existing one if it is present.
Do other values go inand out of the session OK?
 
John Miller
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frank Carver:
How are you getting the session in your servlet? Beware that you can get a session in two ways, one which always creates a new session, and one which will get an existing one if it is present.
Do other values go inand out of the session OK?


Yes the values go into the session, but when I access them in the other class they return null. I do use getSession(true) and getSession(false) in the right palces to prevent creating a new servlet each time.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic