ITeye博客

Java对session的监控

listen-raining · 2015-01-12 15:37 · Java · 编程语言 · Markdown

在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()+
     "******************************************" +
     "******************************************" +
     "******************************************" +
     "*******************************************");
   
  }
 }

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。