⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userlistener.java

📁 :一个用JavaScript开发的用户管理系统。
💻 JAVA
字号:
package test;

import javax.servlet.http.HttpSession;
import javax.servlet.http.*;
import javax.servlet.ServletContext;
import javax.servlet.*;
import java.util.*;

public class UserListener implements HttpSessionListener {
  ServletContext application = null;
  public void sessionCreated(HttpSessionEvent e1){
     application=e1.getSession().getServletContext();
     e1.getSession().setMaxInactiveInterval(120);
     int count=0;
     if(application.getAttribute("count")!=null)
       count=(Integer)application.getAttribute("count");
     count++;
     application.setAttribute("count",new Integer(count));
  }
  public void sessionDestroyed(HttpSessionEvent e2){
     application=e2.getSession().getServletContext();
     Vector vc=(Vector)application.getAttribute("online");
     for(int i=0;i<vc.size();i++){
       String tem=(String)vc.get(i);
       if(tem.equals((String)e2.getSession().getAttribute("user"))){
         vc.removeElementAt(i);
       }
     }
     application.setAttribute("online",vc);
     int count=0;
     count=(Integer)application.getAttribute("count");
     count--;
     application.setAttribute("count",new Integer(count));
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -