I have this Spring application where I have configured the login and logout function to have an advice which logs their time of execution. But I don't know how to log the time when there is session timeout. I am using Apache Tomcat 7 web server and have configured the session timeout in the web.xml file of my web project. Thanks in advance.
            Asked
            
        
        
            Active
            
        
            Viewed 189 times
        
    0
            
            
        
        suchit
        
- 57
 - 9
 
- 
                    Refer the link hope it will provide you the details you need [click here](http://stackoverflow.com/questions/3943368/invoke-method-just-before-session-expires) – Rishal Jun 30 '16 at 15:53
 - 
                    Thanks Rishal, it seems worth a try. – suchit Jun 30 '16 at 15:57
 - 
                    Welcome @suchit ,upvote if it resolves your requirement. – Rishal Jun 30 '16 at 16:38
 - 
                    Sure will do, but I am off work, definitely by tomorrow. – suchit Jun 30 '16 at 17:36
 
1 Answers
0
            
            
        You can resolve this by implementing a javax.servlet.http.HttpSessionListener.
The HttpSessionListener.sessionDestroyed(HttpSessionEvent httpSessionEvent) will be invoked when the session expires.
If you annotate your implementation class with @javax.servlet.annotation.WebListener then Tomcat 7 will install and execute it for you as needed.
        Steve C
        
- 18,876
 - 5
 - 34
 - 37
 
- 
                    Thanks @Steve, I am a newbie to Spring, kept a separate class to implement the HttpSessionListener. Still figuring it out how to weave the same into the application so the overloaded sessionDestroyed method will be called during session expiration. – suchit Jul 01 '16 at 10:25
 - 
                    
 - 
                    I configured it in the web.xml inside listener tag and it worked perfectly. Thanks Steve. – suchit Jul 01 '16 at 11:01