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-INF中的web.xml 之中加入: <web-app> <!-- Listeners --> <listener> <listenerclass>com.test.SessionCounter</listener-class> </listener> </web-app> 再重重新启动服务器就可以统计在线人数了.