Skip to main content

Notification before Session expires/timeout

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2010-06-16

Hi All,
I have an servlet/struts application where I need to limit user login based on some settings. So I have a counter kept to check in ServletContext. Whenever a new session is created acordingly this counter is incremented. When 'logout' happens I am decrementing the counter. But when session expires, this is not happening. Please suggest how to do this. Is there a way to to find session is going to expire ..? If so, at that time can session attributes are accessible..?
Thanks in advance.
Balaji C R B

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-09-23

look at interface javax/servlet/http/HttpSessionListener.html . Create new class implementing this interface, register this class to servlet app runtime - in javadoc is described how, e.g. to web.xml add few rows:
<listener-class>...full class name...</listener-class>

Thats all. In our server we use this listener to map session to user for monitoring all sessions - user, timeout, last access, idle, login time (different to session creation time !), count all etc.
Zdenek Machac

Joined: 2010-06-16

It worked. Thanks a lot :-)