<strong>How to use the session-id to retrieve the Session object?</strong>
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Luca_Ventura
Posted On:   Saturday, December 29, 2001 12:01 PM

Hello everybody! I have the following problem: I have a servlet running in my web-site and many users can connect to it. I want to store all session-id's of users that are surfing im my site in a database. Then I would like to read the session-id of the user from the database and retrieve his session object, but I don't know how to do! In fact In Java API there isn't a method that let me to retrieve a session object using the session-id, but I have only the method getSession() of HttpServletRequest class. My problem is that I DON'T WANT AND I CAN'T USE getSession() method because I need to use a database and in the database I insert session-id's not objects (like an instance of HttpServletRequest class where to apply the method get   More>>

Hello everybody!


I have the following problem: I have a servlet running in my web-site and many users can connect to it. I want to store all session-id's of users that are surfing im my site in a database. Then I would like to read the session-id of the user from the database and retrieve his session object, but I don't know how to do! In fact In Java API there isn't a method that let me to retrieve a session object using the session-id, but I have only the method getSession() of HttpServletRequest class. My problem is that I DON'T WANT AND I CAN'T USE getSession() method because I need to use a database and in the database I insert session-id's not objects (like an instance of HttpServletRequest class where to apply the method getSession() and retrieve the session). Can someone help me? I have read other posts in the forum but I have found no solution yet. Now I am using an hashtable to store the couple (user,session object) but it isn't a good solution because I can have thousands of users connected to my web-site and it is no good idea to store all session object in memory!



Thanks a lot in advance!



Luca

   <<Less

Re: <strong>How to use the session-id to retrieve the Session object?</strong>

Posted By:   ranjith_ayinala  
Posted On:   Friday, January 4, 2002 01:03 AM

The getId() method of HttpSession interface would work for U.But Why do u want to save that in database?In any case U dont need to save ID in database as every request is identified differently and if u invoke get session on request u get session object particular to that user and sessions have limited life span. Also, invoking getId() on that session objec gives u user specific-session id everytime. U can assosiate any other object , say a hashtable or vector with that id and retrieve that object it all thru the session.
About | Sitemap | Contact