zoukankan      html  css  js  c++  java
  • SessionListener失败,退出

    配置如下:

    web.xml:

     <listener>
        <listener-class>cn.edu.hbcf.common.listener.SessionListener</listener-class>
      </listener>

    java类:

    SessionListener.java

    package cn.edu.hbcf.common.listener;
    
    import javax.servlet.http.HttpSession;
    import javax.servlet.http.HttpSessionEvent;
    import javax.servlet.http.HttpSessionListener;
    
    import cn.edu.hbcf.common.constants.WebConstants;
    import cn.edu.hbcf.common.springmvc.SpringContextHolder;
    import cn.edu.hbcf.privilege.dao.BaseUserLogMapper;
    import cn.edu.hbcf.privilege.pojo.BaseUserLog;
    import cn.edu.hbcf.privilege.pojo.BaseUsers;
    
    public class SessionListener implements HttpSessionListener {
    
         @Override  
         public void sessionCreated(HttpSessionEvent arg0) {}  
         @Override  
         public void sessionDestroyed(HttpSessionEvent arg0) { 
             HttpSession session = arg0.getSession();
             BaseUsers user = (BaseUsers)session.getAttribute(WebConstants.CURRENT_USER);
             String name=user.getAccount();   
             if(name!=null && name.length()>0){//session失效时候移除记录    
                 if(SessionAttributeListener.sessionMap.containsKey(name)){
                     BaseUserLogMapper baseUserLogMapper = SpringContextHolder.getBean("baseUserLogMapper");
                     BaseUserLog log = new BaseUserLog();
                     log.setLogType(2);
                     log.setUser(user);
                     log.setDescription("退出成功");
                     baseUserLogMapper.insert(log);
                     SessionAttributeListener.sessionMap.remove(name);   
                 }
            }   
         }
    
    }
  • 相关阅读:
    centos7防火墙那些事
    CentOS7安装mysql数据库
    git回滚到任意版本
    SQL Server查看所有表大小、表行数和占用空间信息
    windows地址转发
    Apache和tomcat服务器使用ajp_proxy模块
    jdk分析工具:jps和jstack
    centos下linux运行asp网站搭建配置-mono+nginx
    reader
    solr课程学习系列-solr服务器配置(2)
  • 原文地址:https://www.cnblogs.com/zrui-xyu/p/4942711.html
Copyright © 2011-2022 走看看