Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Execute Session Destroying code in jsp

 
vishal avad
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when my some bean is holding the scope session. and my user does
not properly logs out instead he presses cross button of the browser. directly then how could i log him out.
or if power goes down.
is there any solution other than using timeout?
 
Manas Ahlaad
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
there is HttpSessionBindingListener which can be associated to a session , it will notify you when session is expired and started.
or else i dont think there is nothing to notify the events such as browser closing, power off
 
vishal avad
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx manas
my question is how to write a code which will be automatically executed when a session is closed in any of the possible ways
 
sanjay yermalkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the session expires (or invalidates), it calls valueUnbound() method on all the bound objects implementing HttpSessionBindingListener. So, you can write a class which implements HttpSessionBindingListener and
have the valueUnbound() method execute the cleanup rutine.
 
vishal avad
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx sanjay
i will try this and get back
thx again

vishal
 
Manas Ahlaad
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sanjay & avad,
valueUnbound() is called when the session expires , but closing the browser does not let the session expire.
If the browser is closed , the session object stays at the server for quite sometime (the idle time specified for the servlet specified in the web.xml file) , if the instance of the servlet idle upto the time then the server removed the instance from container thus causing the session to expire.
try specifying short time in web.xml file
manas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic