• 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

Invalidation HttpSession upon closing the browser

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a clean way out there, to invalidate a user's httpsession when the user closes the browser? I have seen several
Javascript hacks which are not browser compatible. I need something that will work with IE 4.0 + and Netscape 6.0.
Thanks
Alok
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you set the lifetime of the cookie to a negative number it the cookie will be deleted after the browser closes.
------------------
In Gates we trust. Yeah right....
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use session.invalidate() method to invalidate an httpsession.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, but that wont work if the person closes the browser before they get to that line of code. I am wondering what kind of problem it can cause if you dont do anything about it?
 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Randall Twede:
yes, but that wont work if the person closes the browser before they get to that line of code. I am wondering what kind of problem it can cause if you dont do anything about it?



The problem is that, I typically store some objects in the HttpSession and would like to quickly *null* those objects when the session is invalidated.
public MyObject implements HttpSessionBindingListener {
private Map map1,map2,map3;
private List list1,list2;
public MyObject() {
map1 = new HashMap();
map2 = new HashMap();
list1 = new ArrayList();
list2 = new ArrayList();
}
//Method 1
public void valueBound(HttpSessionBindingEvent eve) {
}
//Method 2
public void valueUnBound(HttpSessionBindingEvent eve) {
list1 = null;
list2 = null;
map1 = null;
map2 = null;
map3 = null;
}
}
Method 2 gets called when the session is invalidated. Session is invalidated if the client remains inactive for (say 30 mins). Closing the browser does not allow the container to call method2
immediatly nd it gets called only after 30 mins of inactivity thus holding up unused memory in the list1,list2, map1,map2,map3
objects..
I need a way to signal the conatiner to call method2 as soon as the browser is closed.
Method
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well I suppose if those objects are quite large, or you have mass traffic, it could be a problem. Im sorry I dont have solution, I never had to worry about it.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
You can make use of onunload or onbeforeunload functions ,,write an javascript event to call a servlet to invalidate httsesssion for onBeforeUnLoad .
onBeforeUnload will get trigeered on closing the browser,,,
Regards,
------------------
 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anoosh Rahman:
Hi.
You can make use of onunload or onbeforeunload functions ,,write an javascript event to call a servlet to invalidate httsesssion for onBeforeUnLoad .
onBeforeUnload will get trigeered on closing the browser,,,
Regards,


The thing is "onunload" is called everytime I leave the page that says uses this session object. There is no way to differentiate between an onunload triggered by leaving the page & an onunload triggered by closing the browser.
reply
    Bookmark Topic Watch Topic
  • New Topic