Java对session的监控

在Java中可以使用 javax.servlet.http.HttpSessionAttributeListener 类 来对session进行监控。

 

package com.eshore.ssoserver.sysmgr.action;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

public class AttributeListenTest implements HttpSessionAttributeListener{

 @Override
 public void attributeAdded(HttpSessionBindingEvent arg0) {
  if(arg0.getName().equals("staff")){
   System.out.println("**************************新增session的staff属性值为:" + arg0.getValue()+
     "******************************************" +
     "******************************************" +
     "******************************************" +
     "*******************************************");
   
  }
  
  if(arg0.getName().equals("postId")){
   System.out.println("**************************新增session的postId属性值为:" + arg0.getValue()+
     "******************************************" +
     "******************************************" +
     "******************************************" +
     "*******************************************");
   
  }
  
 }

 @Override
 public void attributeRemoved(HttpSessionBindingEvent arg0) {
  if(arg0.getName().equals("staff")){
   System.out.println("**************************移除session的staff属性值为:" + arg0.getValue()+
     "******************************************" +
     "******************************************" +
     "******************************************" +
     "*******************************************");
   
  }
  
  if(arg0.getName().equals("postId")){
   System.out.println("**************************移除session的postId属性值为:" + arg0.getValue()+
     "******************************************" +
     "******************************************" +
     "******************************************" +
     "*******************************************");
   
  }
  
 }

 @Override
 public void attributeReplaced(HttpSessionBindingEvent arg0) {
  if(arg0.getName().equals("staff")){
   System.out.println("**************************替换session的staff属性值为:" + arg0.getValue()+
     "******************************************" +
     "******************************************" +
     "******************************************" +
     "*******************************************");
   
  }
  
  if(arg0.getName().equals("postId")){
   System.out.println("**************************替换session的postId属性值为:" + arg0.getValue()+
     "******************************************" +
     "******************************************" +
     "******************************************" +
     "*******************************************");
   
  }
 }

}

你可能感兴趣的:(session监控)