import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;public class SessionCounter
    implements HttpSessionListener
{    private static int activeSessions = 0;    public SessionCounter()
    {
    }    public void sessionCreated(HttpSessionEvent se)
    {
        activeSessions++;
    }    public void sessionDestroyed(HttpSessionEvent se)
    {
        if(activeSessions > 0)
            activeSessions--;
    }    public static int getActiveSessions()
    {
        return activeSessions;
    }}在web.xml中,加上这一段:<listener>
  <listener-class>SessionCounter</listener-class>
</listener>