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

📄 userlistener.java

📁 Spring +Web 的完整 MyEclipse 项目源码,使用者可以作为入门材料可以在此基础上深入学习
💻 JAVA
字号:
package login;

import javax.servlet.http.*;

public class UserListener
    implements HttpSessionAttributeListener {
  /**
   * Notification that an attribute has been added to a session.
   *
   * @param se HttpSessionBindingEvent
   * @todo Implement this javax.servlet.http.HttpSessionAttributeListener
   *   method
   */
  int users=0; //当前用户数
  public void attributeAdded(HttpSessionBindingEvent se) {
    if(se.getName().equals("username"))
      {
        users++;
        System.out.println("用户登录,用户名:"+se.getValue());
        System.out.println("当前用户数:"+users);
      }
  }

  /**
   * Notification that an attribute has been removed from a session.
   *
   * @param se HttpSessionBindingEvent
   * @todo Implement this javax.servlet.http.HttpSessionAttributeListener
   *   method
   */
  public void attributeRemoved(HttpSessionBindingEvent se) {
    if(se.getName().equals("username"))
  {
    users--;
    System.out.println("用户注销,用户名:"+se.getValue());
    System.out.println("当前用户数:"+users);
  }

  }

  /**
   * Notification that an attribute has been replaced in a session.
   *
   * @param se HttpSessionBindingEvent
   * @todo Implement this javax.servlet.http.HttpSessionAttributeListener
   *   method
   */
  public void attributeReplaced(HttpSessionBindingEvent se) {
  }
}

⌨️ 快捷键说明

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