一 新建一个类
package com.session;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionListener implements HttpSessionListener {
static int count;
public void sessionCreated(HttpSessionEvent arg0) {
count++;
}
public void sessionDestroyed(HttpSessionEvent arg0) {
count--;
}
/**
* @return the count
*/
public static int getCount() {
return count;
}
}
web.xml中配置
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
com.session.SessionListener
index.jsp
三 调用
My JSP 'index.jsp' starting page 共 人在线