Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalidating a session

 
Kris Parr
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic