package com.test;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/** *//**
* 编写以下SessionCounter.java 并编译为SessiionCounter.class
* 然后放到你的网站的classpath的
* SessionCount(自己建立此目录)下面
*/

public class SessionCounter implements HttpSessionListener
{
private static int activeSessions = 0;

public void sessionCreated(HttpSessionEvent se)
{
activeSessions++;
}

public void sessionDestroyed(HttpSessionEvent se)
{
if (activeSessions > 0)
activeSessions--;
}

public static int getActiveSessions()
{
return activeSessions;
}
}
<web-app>
<!-- Listeners -->
<listener>
<listenerclass>com.test.SessionCounter</listener-class>
</listener>
</web-app>
371

被折叠的 条评论
为什么被折叠?



