The server does not know if the browser has been closed. The session will stay alive until the servlet engine is shut down.
Joined: Dec 15, 2001
Then how should we handle this? I mean how do we intelligently maintain a session?
Joined: Jan 26, 2002
The servlet engine is doing all the hard work of maintaining the session for you using either cookies or URL rewriting. The maxInactiveInterval (defaults to 20 minutes) will mean that if the client doesn't send another request for 20 minutes, the servlet engine is free to expire that session. If you have high demand then you might end up with a build up of "stale" sessions. You could shorten the interval, but take into account that if the interval was a few seconds, then every time they paused to think, their session would time-out on them. If you don't have high demand you could maybe make the maxInactiveInterval longer so they could go away and cook their dinner before completing purchase of Widgets from your online store. If you do change maxInactiveInterval, I recommend changing it in the web.xml. There is a <session-config> parameter called <session-timeout> that will have the same effect.