• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do i clear the http session data when the user closes the browser.
Can i invalidate a user session when the user closes the browser.
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I dont know the exact code but u can do it as follows

1 handel windows (browser)close event
2 call a javascript function on it and send request to some jsp
on server which will invalidate the session.

Cheers
-Praful
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think handling the close event of browser is very efficient.

eg: I press CTRL + N during any session and new window gets open with same session. I perform any operation on new window same time old window is open.

but closing any window will kill my session, and being a user I will not like it.
[ October 27, 2004: Message edited by: Shailesh Chandra ]
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cant use Javascript function to invalidate session when the user closes the browser.

The cross browser JavaScript you can possibly use is the onUnload() event. This event gets fired whenever the current page being shown is about to be changed. Most browsers fire it when you close the browser, but it will also be fired when you move from one page to next. So, you cant reliably use it to detect a browser being closed.

The best thing to do is to set the session time out appropriately for your web app. It has been discussed many times before.
Try doing a google search of Javaranch forums
http://www.google.com.my/search?q=browser+close+session+invalidate+site%3Asaloon.javaranch.com
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

shouldn't be the javascript soluiton. ofcourse you should do that always. but again its on client-end. Moreover, javascript may vary browser to browser.

its better to use HttpSessionListener. and invalidate the session on logout and session-timeout. it will definitely work in any case. but ofcourse session-timeout might not be the real logout time for the user. you can use javascript solution along this one.

cheers
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic