Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalidate session when browser is closed

 
Jordan Smith
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i would like to invalidate the session when the browser/tab is closed by the user.

i thought that maybe using ajax will make it but i don't know how.

how can i do it?
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to send an AJAX request to the server using the onunload event of the body. Look on google to find a good tutorial on AJAX like this or this or this...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That probably wouldn't work if the browser crashes, but I'm not sure. You could also send a periodic request from every page (like once a minute or something) and if that "keepalive" request doesn't come in the session is invalidated.
 
Jordan Smith
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i send a periodic request from every page?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start a periodic timer, and when it fires, make an ajax request to find out if the session has expired.

The app would need to keep track of sessions to make sure each session gets its respective periodic request.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
odelya yomtov wrote:
i would like to invalidate the session when the browser/tab is closed by the user.


Unfortunately,there is no way for a server to detect the event.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic