This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes Session does not persist Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Session does not persist" Watch "Session does not persist" New topic
Author

Session does not persist

John Miller
Greenhorn

Joined: May 24, 2001
Posts: 12
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");
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
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?


A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
John Miller
Greenhorn

Joined: May 24, 2001
Posts: 12
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Session does not persist
 
Similar Threads
RequestDispatcher.forward problem
Servlets
Servlets and the session
Servlets and the session
The Session