📄 sessionlistener.java
字号:
/*
* SessionListener.java
*
* Created on 2007年10月19日, 下午4:24
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.servlet;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
public class SessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent evt) {
// 修改在线人数
String current= (String)evt.getSession().getServletContext().getAttribute("online");
if(current==null)current="0";
int c=Integer.parseInt(current);
c++;
current=String.valueOf(c);
evt.getSession().getServletContext().setAttribute("online",current);
//修改历史人数
String his= (String)evt.getSession().getServletContext().getAttribute("Counter");
if(his==null)his="0";
int total=Integer.parseInt(his)+1;
his=String.valueOf(total);
evt.getSession().getServletContext().setAttribute("Counter",his);
}
public void sessionDestroyed(HttpSessionEvent evt) {
// TODO 在此处添加您的代码:
// 修改在线人数
String current= (String)evt.getSession().getServletContext().getAttribute("online");
if(current==null)current="0";
int c=Integer.parseInt(current);
c--;
current=String.valueOf(c);
evt.getSession().getServletContext().setAttribute("online",current);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -