| Author |
Maintain Session
|
aakash bhatt
Ranch Hand
Joined: Jan 09, 2003
Posts: 182
|
|
If HTTP is staleless protocol then how does it maintain Session through HttpSession Thanks, aakash
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
|
The server uses a session cookie (stored in the user's browser), or, sometimes a url parameter to match the user up to a session object (stored in memory on the server).
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
aakash bhatt
Ranch Hand
Joined: Jan 09, 2003
Posts: 182
|
|
Thanks Ben, With cookie and Url paramter we can maintain session indirectly. But my query is as Http is a staless protocol then how does we can maintain a sesion by setting values in HttpSession, then how does in this HTTP protcol handle it. Thanks, aakash
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Yes, HTTP is stateless. That means the server has to check for a sessionId in every request that comes in (either as a cookie header or as a url parameter). If it finds one, it checks to see if there is an object, stored in session, with a matching id. If not, then it creates a new object and sends the ID back to the browser in the response. The HTTP protocol doesn't handle it. The servlet container mimicks a stateful session with this technique. If you're asking how to save objects in session, read up on the HttpSession's getAttribute and setAttribute methods. http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html
|
 |
 |
|
|
subject: Maintain Session
|
|
|