LoggedUserCounter.java
上传用户:lsj999sz
上传日期:2022-06-15
资源大小:4717k
文件大小:1k
源码类别:

ICQ/即时通讯

开发平台:

Java

  1. package com.bjsxt.shopping.util.listener;
  2. import javax.servlet.http.HttpSessionAttributeListener;
  3. import javax.servlet.http.HttpSessionBindingEvent;
  4. import javax.servlet.http.HttpSessionEvent;
  5. import javax.servlet.http.HttpSessionListener;
  6. public class LoggedUserCounter implements HttpSessionListener, HttpSessionAttributeListener {
  7. private static int count = 0;
  8. public void sessionCreated(HttpSessionEvent event) {
  9. System.out.println("------------session created!");
  10. }
  11. public void sessionDestroyed(HttpSessionEvent event) {
  12. }
  13. public void attributeAdded(HttpSessionBindingEvent event) {
  14. if(event.getName().equals("admin") && ((String)event.getValue()).equals("admin")) {
  15. count ++;
  16. System.out.println("a user logged in ! now total :" + count);
  17. }
  18. }
  19. public void attributeRemoved(HttpSessionBindingEvent arg0) {
  20. }
  21. public void attributeReplaced(HttpSessionBindingEvent arg0) {
  22. }
  23. }