码迷,mamicode.com
首页 > 编程语言 > 详细

Java web Session 监听类。

时间:2014-04-30 22:31:38      阅读:397      评论:0      收藏:0      [点我收藏+]

标签:sessionlistenser   会话管理   

public class SessionListener implements HttpSessionListener {
	
	static Logger log = Logger.getLogger(
			SessionListener.class.getName());
    private static Map<String, HttpSession> map = new   
            HashMap<String, HttpSession>();  
	static private int sessionCount = 0;
	    public void sessionCreated(HttpSessionEvent event) {
	        String id = event.getSession().getId();  
            log.debug("session created : " + id);  
	        synchronized (this) {
	            sessionCount++;
	            map.put(id, event.getSession());
	        }
	 
	       log.info("Session Created: " + event.getSession().getId());
	       log.info("Total Sessions: " + sessionCount);
	    }
	 
	    public void sessionDestroyed(HttpSessionEvent event) {
	        synchronized (this) {
	            sessionCount--;
	        }
	        log.info("Session Destroyed: " + event.getSession().getId());
	        log.info("Total Sessions: " + sessionCount);
	    }
	    public static HttpSession getHttpSession(String sessionID)  
	    {  
	        return map.get(sessionID);  
	    }
}

in web.xml

 

 <listener>
		<listener-class>com.ipcs.listener.SessionListener</listener-class>
	  </listener>

参考页面:http://www.coderanch.com/t/365859/Servlets/java/session-object-session-ID

Java web Session 监听类。

标签:sessionlistenser   会话管理   

原文地址:http://blog.csdn.net/xiaohelong2005/article/details/24780465

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!