@WebListener()publicclassHttpSessionListenerUtilimplementsHttpSessionListener, HttpSessionAttributeListener {// -------------------------------------------------------// HttpSessionListener implementation// -------------------------------------------------------// 监听session何时创建publicvoidsessionCreated(HttpSessionEvent se){/* Session is created. */
System.out.println("session 创建了 。。。。。。。");
System.out.println("------------"+se.getSession().getId());
System.out.println("---------"+ se.getSession().getAttribute("session_user"));
System.out.println("==========================================================");}// 监听session销毁的时机publicvoidsessionDestroyed(HttpSessionEvent se){/* Session is destroyed. */
System.out.println(" session 销毁了。。。。。。。");
System.out.println(" *************"+ se.getSession().getAttribute("session_user"));
System.out.println("========================================");}// -------------------------------------------------------// HttpSessionAttributeListener implementation// -------------------------------------------------------// 监听session域中何时存值publicvoidattributeAdded(HttpSessionBindingEvent sbe){/* This method is called when an attribute
is added to a session.
*/
System.out.println(" session域中 添加属性值了。。。。。");// 获取放进session域中的key值
System.out.println("key值: "+ sbe.getName());// 获取放进session域中的value值
System.out.println("value值: "+ sbe.getValue());
System.out.println("================================");}// 监听 删除从session域中存储的值publicvoidattributeRemoved(HttpSessionBindingEvent sbe){/* This method is called when an attribute
is removed from a session.
*/
System.out.println("session 域中 开始删除值了。。。。。");
System.out.println(sbe.getName());
System.out.println(sbe.getValue());
System.out.println("===================================");}publicvoidattributeReplaced(HttpSessionBindingEvent sbe){/* This method is invoked when an attribute
is replaced in a session.
*/}}