📄 userlistener.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 + -