首先寫個類:
import javax
import javax
public class SessionCounter implements HttpSessionListener {
private static int activeSessions =
public void sessionCreated(HttpSessionEvent se) {
activeSessions++;
}
public void sessionDestroyed(HttpSessionEvent se) {
if(activeSessions >
activeSessions
}
public static int getActiveSessions() {
return activeSessions;
}
}
然後配置web
<?xml version="
<web
xmlns="
xmlns:xsi="
xsi:schemaLocation="
****************************************
<!
<listener>
<listener
SessionCount
</listener
</listener>
*****************************************
</web
建個JSP測試:
test
<%@ page language="Java" contentType="text/html;charset=GBK"%>
<%@ page import="java
<%@ page import="SessionCount
<html>
<head>
<meta http
<title>無標題文檔</title>
<body bgcolor="#FFFFFF">
在線人數:<%=SessionCounter
</body>
</html>
測試以下
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25508.html