wood burning stoves*
The moose likes Servlets and the fly likes Invalidating a session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Invalidating a session" Watch "Invalidating a session" New topic
Author

Invalidating a session

Kris Parr
Greenhorn

Joined: Aug 13, 2001
Posts: 8
I need to invalidate a session when the browser window is closed. I've looked at using the onUnload event but this doesn't seem to be able to submit a form to a servlet. Using a JSP Method seems to execute the method on compilation and not wait for the event to trigger. Any ideas on how I can achieve this ?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
There is no guaranteed method for doing exactly what you want. You could put a short lifetime on the session and use some sort of "heartbeat" applet or Javascript on the page to keep it alive.
Bill

------------------
author of:
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
I just went thru this same problem building a who's on type program. You can use the onUnload event BUT it will trigger everytime the user changes pages. I actually had a script working that ran them thru a logout servlet with the onUnload event (Javascript) but it turned out to be a major headache so I scrapped it & we went with a ServletBindingListener class & set the session.setMaxInactiveInterval() method so that if no session activity was detected for 15 minutes the valueUnbound method was called & wrote to the database to log the user out. Its really not as hard as you would think, tough I must admit I sought outside help for it. What you are trying to do with Javascript is next to impossible because your JavaSCript object exist on the clients machine, hence when the browser is closed the object dies....You can do just about anything with a ServletBindingListener class because no matter what the user does (wander off the site, close the browser, etc) The valueUnbound method of your listener still exists & the object itself will exist until it does what you want it to because it resides on the server.........hope this helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalidating a session
 
Similar Threads
Not recieving sessionDestroyed on Browser close
Not able to read the big string value in StAX Parsing
Hibernate problem
Problems with HttpSessionBindingListener
How to kill the session on browser close