sessionlistener.java
来自「介绍了j2ee开发常用的学习知识,如servlet,javamail,EJB等知」· Java 代码 · 共 42 行
JAVA
42 行
/*
* 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 + =
减小字号Ctrl + -
显示快捷键?