I working with JSP.
I need run a method in ever session closing, i.e., whenever the browser is closed.
how do I make this?
Asked
Active
Viewed 541 times
1

HagaHood
- 199
- 2
- 9
-
2post you code what you have tried? – Shriram Feb 22 '16 at 12:28
-
@HagaHood try see this solution for help, http://stackoverflow.com/a/3943485/5593725 – PT Vyas Feb 22 '16 at 12:36
2 Answers
1
On server-side you can register an HttpSessionListener:
package com.example
public class MySessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
System.out.println("Session created");
}
public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("Session destroyed");
}
}
To register you can either add @WebListener annotation to the listner's class or add the listener to web.xml
<listener>
<listener-class>com.example.MySessionListener</listener-class>
</listener>
The listener won't be called in the moment when the browser is closed it will be called when the session is timed out.

Neothorn
- 329
- 1
- 7
0
You have to detect the browser close event in javascript.see Trying to detect browser close event to detect browser close event
Send ajax call to serverside which will invalidate the session