zoukankan      html  css  js  c++  java
  • ssession监听器 .

    ssession监听器 .
    session监听器 .
    分类: java 2006-12-05 16:48 1288人阅读 评论(1) 收藏 举报
    1.HttpSessionBindingListener:
                        在把实现了该接口的对象往session.setAttribute里面放的时候触发valueBound

    时间,在session.invalidate()或超过时间限制的时候触发valueUnbound,该监听器不要配置web.xml。

    2.
    HttpSessionAttributeListener :
               任何进行session.setAttribute的时候分别触发attributeAdded(),attributeReplaced()事

    件。在session.removetAttribute的时候触发attributeRemoved()。要在web.xml配置Listener 。

    3.
    HttpSessionListener :
    在session创建的时候就触发sessionCreated,在session.invalidate()或超过时间限制的时候触发

    sessionDestroyed。要在web.xml配置Listener 。

    例子:
    web.xml配置:
            <!-- 用户注销session监听器 :必须放在com.huawei.bme.web.context.SessionListener之

    前-->
     <listener>
      <listener-class>
       com.huawei.common.listener.LoginSessionListener
      </listener-class>
     </listener>
     
     <listener>    
        <listener-class>com.huawei.bme.web.context.SessionListener</listener-class>
     </listener>监听器处理类:
    public class LoginSessionListener implements HttpSessionListener
    {
        public void sessionCreated(HttpSessionEvent event)
        {
           
        }
       
        public void sessionDestroyed(HttpSessionEvent event)
        {
            UserProfile userProfile = (UserProfile)event.getSession().getAttribute

    (Constant.USER_LOGIN_MSG);
            String userAccount = "";
            String loginIp = "";
            if (null != userProfile)
            {
                userAccount = userProfile.getUserAccount();
                System.out.println("userAccount:"+userAccount);
                loginIp = event.getSession().getAttribute("LoginIp").toString();
                System.out.println("loginIp:"+loginIp);
                try
                {
                    insertUserLogoutLog(userAccount, loginIp);
                }
                catch (PortalException e)
                {
                    DebugLogFactory.error(this.getClass(),
                        "insertUserLogoutLog error", e);
                }
            }
        }

  • 相关阅读:
    redis配置文件 redis.conf
    CentOS安装 NodeJS 和 NPM
    Docker中运行redis报错误: Failed opening the RDB file root (in server root dir /etc/cron.d) for saving: Permission denied
    AllowControlAllowOrigin:谷歌跨域扩展插件下载
    uniapp 判断客户端环境是安卓还是ios
    Windows环境下查看某个端口被哪个应用程序占用并停止程序
    Oracle数据库快速入门
    Linux 使用vim命令编辑文件内容
    解决VMware Workstation客户机与宿主机无法复制文件和共享剪切板的问题
    Spring 中的事件机制 ApplicationEventPublisher
  • 原文地址:https://www.cnblogs.com/qqzy168/p/3137004.html
Copyright © 2011-2022 走看看