临窗旋墨的博客       临窗旋墨的导航

Session监听事件的处理

 设置Session监听
 在web.xml文件中:

  1. <listener>  
  2.        <listener-class>cjq.login.listener.UpdateLogOutTimerListener</listener-class>  
  3. </listener>  
  4.     <session-config><!-- session 失效的时间,单位:分钟-->  
  5.         <session-timeout>30</session-timeout>  
  6.     </session-config>  


 

 


java代码处理如下:

    1. public class UpdateLogOutTimerListener implements HttpSessionListener{  
    2.   
    3.  public void sessionCreated(HttpSessionEvent arg0) {  
    4.   // TODO Auto-generated method stub  
    5.   //此处为session创建时要做的功能  
    6.  }  
    7.   
    8.  public void sessionDestroyed(HttpSessionEvent se) {  
    9.   // TODO Auto-generated method stub  
    10.   HttpSession session = se.getSession();  
    11.   if(session != null){  
    12.    SessionBean sb = (SessionBean)session.getAttribute("SessionBean");  
    13.    if(sb != null){  
    14.     LogUserInfo userInfo = sb.getUserInfo();  
    15.     if(userInfo != null){  
    16.      String account = userInfo.getAccount();  
    17.      IOSysConfigParamUCC paramUCC = new OSysConfigParamUCCImpl();  
    18.      paramUCC.updateCurrentNum(0);  
    19.     }  
    20.    }  
    21.   }  
    22.  }  
    23.   
posted @ 2015-02-05 17:11  临窗旋墨  阅读(901)  评论(0编辑  收藏  举报