Skip to main content

Notification before Session expires/timeout

2 replies [Last post]
balajicrb
Offline
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.
xmachac2
Offline
Joined: 2003-09-23

Hi,
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>
<listener-class>...full class name...</listener-class>
</listener>

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

balajicrb
Offline
Joined: 2010-06-16

Hello,
It worked. Thanks a lot :-)
--balaji