首先寫個類:
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=
<%@ page import=
<%@ page import=
<html>
<head>
<meta http
<title>無標題文檔</title>
<body bgcolor=
在線人數:<%=SessionCounter
</body>
</html>
看看可以實現不?我也是找到的
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26859.html