设置Session监听
在web.xml文件中:
- <listener>
- <listener-class>cjq.login.listener.UpdateLogOutTimerListener</listener-class>
- </listener>
- <session-config><!-- session 失效的时间,单位:分钟-->
- <session-timeout>30</session-timeout>
- </session-config>
java代码处理如下:
- public class UpdateLogOutTimerListener implements HttpSessionListener{
- public void sessionCreated(HttpSessionEvent arg0) {
- // TODO Auto-generated method stub
- //此处为session创建时要做的功能
- }
- public void sessionDestroyed(HttpSessionEvent se) {
- // TODO Auto-generated method stub
- HttpSession session = se.getSession();
- if(session != null){
- SessionBean sb = (SessionBean)session.getAttribute("SessionBean");
- if(sb != null){
- LogUserInfo userInfo = sb.getUserInfo();
- if(userInfo != null){
- String account = userInfo.getAccount();
- IOSysConfigParamUCC paramUCC = new OSysConfigParamUCCImpl();
- paramUCC.updateCurrentNum(0);
- }
- }
- }
- }
- }