userlistener.java
来自「Spring +Web 的完整 MyEclipse 项目源码,使用者可以作为入门」· Java 代码 · 共 51 行
JAVA
51 行
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 + =
减小字号Ctrl + -
显示快捷键?