Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session time out

 
gas das
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
I have problems with session time out,
I'd like to know if there's a way to intercept session expire event.
In my web xml I have <session-timeout>20</session-timeout>
and it works, but I want to do call a function that use a session attribute before the session will be invalidated.
This function get userId from session and notify on database the user logout.
Do you know if I can map in my web-xml an handler,listener or something else?
Thanks a lot
Navert
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you keep reference to everything that needs to be cleaned up in an object that implements SessionBindingListener and is held in the session, then all of your cleanup can be done in the valueUnbound() method. This does not have to be declared in web.xml - in contrast to other types of listener.

When valueUnbound is called, you can NOT rely on any other part of the session being valid, thats why I say this object has to keep its own references to things that are used in cleanup.

Bill
 
Darren Edwards
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a class which implements the HttpSessionLIstener interface and add it to the web.xml

 
Harpreet Hira
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare the listener in web.xml as described by Darren.
In the implementation class, put your cleanup-code in sessionDestroyed(HttpSessionEvent) method. This method is called by the container just before the session is invalidated.
 
gas das
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok great! I used HttpSessionListener and it works. thanks to all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic