This might help:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SessionTracker
implements HttpSessionBindingListener
{
public void valueBound(HttpSessionBindingEvent event)
{
System.out.println("ADDED session " + event.getSession().getId() );
}
public void valueUnbound(HttpSessionBindingEvent event)
{
String sqlStatement = new String("delete from session_data ");
sqlStatement += " where session_id = '" + event.getSession().getId() + "' " ;
super.sendCommand(sqlStatement);
super.sendCommand("commit");
System.out.println("REMOVED session " + event.getSession().getId() );
}
}
Originally posted by Andreas Johansson:
Hi!
I have a servlet that talks with my server to get the pages to show. For the server to know how to generate the pages from the database it stores one data object for every session.
But how do I know when the sessions end? (either when the user logs off, are inactive for 30min or closes the browser). I then want to remove the object on the server and also "log off" the user.
Can I get an event or is some method automatically called when an session ends?
I use servlets with tea and tomcat.
I hope you can help me soon!!
/Andreas