File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how does the server expire the session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how does the server expire the session" Watch "how does the server expire the session" New topic
Author

how does the server expire the session

Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
Can any one tell me When a client request an jsp site from the server
The server will generate a seperate session Id for each client.
this is general
My question is How does the server detect that the client has closed the
explorer to expire the session ?
sangeetha


Regards,Vasantha<p>Great minds discuss ideas. Average minds discuss events. Small minds discuss people.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
the server doesn't.
It maintains a list of active sessions with a timestamp when the last access was.
Whenever a request is made the entry for that session is updated with a fresh timestamp (or a new entry made if it's a new session).
At regular intervals this list is polled to see which sessions haven't been accessed in the set timeout period, and those sessions are killed.
How this is implemented will of course differ between server implementations.


42
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Hi..
The session also resides in the user system as a Cookie & on the server & they are name-value pairs..as soon as the user closes the explorer..the cookie is lost & the container removes the session.
This all stuff is handled by the container..
hth
MB


Malhar Barai
SOA & Java Book
S. Ganapathy
Ranch Hand

Joined: Mar 26, 2003
Posts: 194
Session can be invalidated by two methods. First is the server finds the last accessed time of the session(time stamp) and the current time , and finds the difference, and matches with the session time out parameter configured in webserver configuration file, or the explicitly set value for that particular session.
Second one is user can invalidate their session by invoking invalidate() method on the session object by the user.
regards,
Ganapathy,S
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Originally posted by Malhar Barai:
Hi..
The session also resides in the user system as a Cookie & on the server & they are name-value pairs..as soon as the user closes the explorer..the cookie is lost & the container removes the session.
This all stuff is handled by the container..
hth
MB

You're quite wrong there...
You will have to tell the server explicitly that you're closing the browser or it will never know until the session timeout occurs.
There is no "magic" by which the browser tells the server it is closing unless you specifically code an onunload event into your HTML that does a final request telling the server what's going on.
Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
Hi,
If the session is stored in cookie.Does the user browser save that cookie
in the client side ???

Regards,
Sangeetha
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by Jeroen Wenting:

You're quite wrong there...
You will have to tell the server explicitly that you're closing the browser or it will never know until the session timeout occurs.
There is no "magic" by which the browser tells the server it is closing unless you specifically code an onunload event into your HTML that does a final request telling the server what's going on.

Hi Jeroen...
Maybe I would agree to you on this...
But I had read it somewhere, & I am trying to get the source of it...else how would the container know when the browser has closed, if you hv noted that the session is lost on closing the browser..
Will get back to you as soon as I get the source...
& Sangeetha, the session is indeed refrenced by a cookie that resides on the client-side..
MB
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Hi...
Check out this Thread
hth
MB
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

When the browser is closed there is no way the server will come to know about it. It is only when the session times out the session dies.


Groovy
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399

It may also be worth noting that session cookies are typically resident in memory only and disappear when the browser is closed, but they don't have to be

from this thread
still I m looking fr something to suffice my statement, & I dont say that I'm cent percent right..
Hope you all agree that the session is lost when browser is closed...how does this happen then...??
MB
[ November 28, 2003: Message edited by: Malhar Barai ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Hope you all agree that the session is lost when browser is closed...how does this happen then...??

The cookie is lost when the browser is closed.
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
oops...
I got it wrong...indeed the cookie is lost...thats what I stated in my first post..

as soon as the user closes the explorer(browser)..the cookie is lost

I lose my 0.02 cents...
MB
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

& the container removes the session

This is what you got it wrong in the first post.
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
yup..agreed..
The container doesnt remove the session...but it gets expired after some time that is specified, & they are maintained in Hashtable...
So..am I right now..
MB
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how does the server expire the session