LoggedUserCounter.java
资源名称:Shopping.rar [点击查看]
上传用户:lsj999sz
上传日期:2022-06-15
资源大小:4717k
文件大小:1k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package com.bjsxt.shopping.util.listener;
- import javax.servlet.http.HttpSessionAttributeListener;
- import javax.servlet.http.HttpSessionBindingEvent;
- import javax.servlet.http.HttpSessionEvent;
- import javax.servlet.http.HttpSessionListener;
- public class LoggedUserCounter implements HttpSessionListener, HttpSessionAttributeListener {
- private static int count = 0;
- public void sessionCreated(HttpSessionEvent event) {
- System.out.println("------------session created!");
- }
- public void sessionDestroyed(HttpSessionEvent event) {
- }
- public void attributeAdded(HttpSessionBindingEvent event) {
- if(event.getName().equals("admin") && ((String)event.getValue()).equals("admin")) {
- count ++;
- System.out.println("a user logged in ! now total :" + count);
- }
- }
- public void attributeRemoved(HttpSessionBindingEvent arg0) {
- }
- public void attributeReplaced(HttpSessionBindingEvent arg0) {
- }
- }