關於session監聽瀏覽器關閉服務器執行destory的證實

session監聽初次訪問的時候會生成session放在cookie裏

瀏覽器關閉 服務器延遲執行destory

tomcat8+spring4

public class SessionHelpListen implements HttpSessionListener 
{
	private final String FORMAT = "yy-MM-dd HH:mm:ss";
	public void sessionCreated(HttpSessionEvent sce) 
	{
		System.out.println("創建session:"+DateUtil.getStringNowTime(new Date(),FORMAT));
		WebApplicationContext appctx = WebApplicationContextUtils.getWebApplicationContext(sce.getSession().getServletContext());
		SessionTestService asi = (SessionTestService)appctx.getBean("test");
		SessionTest st = new SessionTest();
		st.setUpdateTime(DateUtil.getStringNowTime(new Date(),FORMAT));
		st.setSessionId(sce.getSession().getId());
		asi.insertSessionMsg(st);
	}
	
	public void sessionDestroyed(HttpSessionEvent sce) 
	{
		System.out.println("銷燬session:"+DateUtil.getStringNowTime(new Date(),FORMAT));
		WebApplicationContext appctx = WebApplicationContextUtils.getWebApplicationContext(sce.getSession().getServletContext());
		SessionTestService asi = (SessionTestService)appctx.getBean("test");
		SessionTest st = new SessionTest();
		st.setSessionId(sce.getSession().getId());
		asi.deleteSessionMsg(st);
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章