forumonlinecount.java
来自「struts+hibernate BBS mysql数据库 功能基本齐全」· Java 代码 · 共 28 行
JAVA
28 行
package com.elan.forum.listener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class ForumOnlineCount implements HttpSessionListener {
private static int count = 0;
private static int high = 0;
public synchronized void sessionCreated(HttpSessionEvent hse) {
hse.getSession().getServletContext().setAttribute("FourmOnline", ++count);
if(count > high ) {
high = count;
}
System.out.println("有用户访问");
}
public synchronized void sessionDestroyed(HttpSessionEvent hse) {
if(count > 0) {
count--;
}
hse.getSession().getServletContext().setAttribute("FourmOnline", count);
System.out.println("有用户退出");
}
public static int getHigh() {
return high;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?