Can one run a method in java or javascript before the allocated tomcat session expires? For ex. User 1’s sessions expires which will in turn ‘trigger’ a method to run before it expires? So my question is, is there any way to tell if the sessions expires (ex. session exception) which will then trigger a function to be run?
I would appreciate it if someone could help me out, thanks.
Yes you can do using
HttpSessionListener#sessionDestroyed()method.Create a class that implements
HttpSessionListenerinterface, and add your code inside the methodsessionCreated(HttpSessionEvent sessionEvent)See the links Session Listener Example and Session Listener Example 2
And nevertheless Javadocs are always there
From javadoc: