• Listener


    通过Listner获得当前的用户个数

    package listener;
    
    import javax.servlet.ServletContext;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    import javax.servlet.http.HttpSessionEvent;
    import javax.servlet.http.HttpSessionListener;
    
    public class OnlineUsers implements ServletContextListener,HttpSessionListener{
        private int count;
        private ServletContext cxt;
        @Override
        public void sessionCreated(HttpSessionEvent arg0) {
            // TODO Auto-generated method stub
            count++;
            cxt.setAttribute("count", new Integer(count));
        }
    
        @Override
        public void sessionDestroyed(HttpSessionEvent arg0) {
            // TODO Auto-generated method stub
            count--;
            cxt.setAttribute("count", new Integer(count));
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent arg0) {
            // TODO Auto-generated method stub
            cxt = null;
        }
    
        @Override
        public void contextInitialized(ServletContextEvent arg0) {
            // TODO Auto-generated method stub
            cxt = arg0.getServletContext();    
        }
        
    }
  • 相关阅读:
    Python深拷贝和浅拷贝解析
    python中count函数的用法
    Jenkins + gitlab + maven 自动打包部署项目
    nio和bio得区别
    nginx负载均衡的5种策略
    接口测试常见bug
    接口自动化面试4
    pass 语句
    if 语句
    while循环
  • 原文地址:https://www.cnblogs.com/da-peng/p/5780886.html
Copyright © 2020-2023  润新知