06d2c3fdac774b943f461cbb0fca041fa8449a84.svn-base 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.sinosoft.lz.system;
  2. import java.util.Date;
  3. import javax.servlet.http.HttpSession;
  4. import javax.servlet.http.HttpSessionEvent;
  5. import javax.servlet.http.HttpSessionListener;
  6. public class LZListener implements HttpSessionListener{
  7. private int sessionCount;
  8. public LZListener() {
  9. this.sessionCount = 0;
  10. }
  11. @SuppressWarnings("unused")
  12. public void sessionCreated(HttpSessionEvent se) {
  13. HttpSession session = se.getSession();
  14. session.setMaxInactiveInterval(60);
  15. synchronized (this) {
  16. sessionCount++;
  17. }
  18. String id = session.getId();
  19. Date now = new Date();
  20. String message = new StringBuffer("New Session created on ").append(now.toString())
  21. .append("\nID: ").append(id).append("\n").append("There are now ")
  22. .append("" + sessionCount).append(" live sessions in the application.").toString();
  23. }
  24. @SuppressWarnings("unused")
  25. public void sessionDestroyed(HttpSessionEvent se) {
  26. HttpSession session = se.getSession();
  27. String id = session.getId();
  28. synchronized (this) {
  29. --sessionCount;
  30. }
  31. String message = new StringBuffer("Session destroyed"
  32. + "\nValue of destroyed session ID is").append("" + id).append("\n")
  33. .append("There are now ").append("" + sessionCount)
  34. .append(" live sessions in the application.").toString();
  35. }
  36. }