Reputation: 132
I am new to Programming
I searched a lot in online but no one could satisfy my requirement.Here I want to delate data from database when user close the browser window.
Here i found one solution in stack overflow
public class YourHttpSessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
//put row in the database
}
public void sessionDestroyed(HttpSessionEvent event) {
//delete the row from database
System.out.println("entered in to listener class");
}
}
and I add in web.xml these lines
<listener>
<listener-class>YourHttpSessionListener</listener-class>
</listener>
Here i don't use any ajax call or some else.But here the sessionDestroyed () is not called when closing the browser.Here i didn't create any sessions.
Upvotes: 0
Views: 127
Reputation: 10285
You are asking the wrong question. The ultimate question should b: Why do you store temporary data in the database? surely, you can do it in a way which does not store anything in the database but keep it in the memory for example
Upvotes: 1
Reputation: 8130
Ultimately, you can't. A better alternative is to write a process that deletes data after a period of user inactivity.
Upvotes: 1