This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes How to Destroy a Session when the user close the browser 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 » Frameworks » Struts
Bookmark "How to Destroy a Session when the user close the browser" Watch "How to Destroy a Session when the user close the browser" New topic
Author

How to Destroy a Session when the user close the browser

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Hi

If suppose the user close the browser how to destroy the session. Please assist me.

I tried with some simple code



Please help me. How can I implement this ?
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Why do you want to this.. when servers supports session time-out feature ?


- Chinna
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
I need this functionality because if suppose I set the timeout as 5 min and if the user closed the browser in 2 min and again if he/she tried to login then it will be a problem. My application will allow 1 session per user. so the user cannot login for next 3min..

This is a bad approach. So as soon as the browser closed the I need to clear the session.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

One solution could be to use *Cookies*.

Another way could be.. on window close.. you can to send a ajax request instead of submitting the form.
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Please give some samples ajax request.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

http://binodsuman.blogspot.com/2009/05/get-start-with-ajax-ajax-siimple.html
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Chinna Many thanks....It's worked

this code helps me

Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Cool..
 
jQuery in Action, 2nd edition
 
subject: How to Destroy a Session when the user close the browser
 
Similar Threads
destroying session when user closes browser
display message when close the brower window
Enabling and disabling Check Boxes
Problem with IE7
Enabling / disabling forms (Struts)