File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Sessions in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sessions in JSP" Watch "Sessions in JSP" New topic

Sessions in JSP

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
How can i be notified that my client has left my page or has closed the explorer window so that i can perform some task before invalidating his session.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
With a normal structure of user request - server response, you can't tell what the user is doing. If you absolutely have to know when the user has "left" - you could put an invisible applet on the page that keeps up a "heartbeat" of requests - but thats a lot of trouble.
If all you need to do is some upkeep before the servlet engine invalidates the session by timing out, look into the
HttpSessionBindingListener interface
which can be notified when the session is about to be destroyed.

author of:
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
Moid: Please read the username policy of JavaRanch. In particular single name usernames are not permitted. Thanks.
The policy, which must be adhered to, is at
Thanks again and welcome to JavaRanch.
Sheriff Tony

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
I agree. Here's the link:
subject: Sessions in JSP
jQuery in Action, 3rd edition