package org.Rudiment.Listener; import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; public class MySessionListener implements HttpSessionListener, HttpSessionAttributeListener { @Override public void sessionCreated(HttpSessionEvent arg0) { System.out.println("新會話建立" + arg0.getSession().getId()); } @Override public void sessionDestroyed(HttpSessionEvent arg0) { System.out.println("有一個會話被銷毀了" + arg0.getSession().getId()); } @Override public void attributeAdded(HttpSessionBindingEvent arg0) { System.out.println("會話:" + arg0.getSession().getId() + "中新增加了一個參數:" + arg0.getName() + " 其數值為:" + arg0.getValue()); } @Override public void attributeRemoved(HttpSessionBindingEvent arg0) { System.out.println("會話:" + arg0.getSession().getId() + "中刪除了一個參數:" + arg0.getName() + " 其數值為:" + arg0.getValue()); } @Override public void attributeReplaced(HttpSessionBindingEvent arg0) { System.out.println("會話:" + arg0.getSession().getId() + "中新一個參數:" + arg0.getName() + " 數值更新為:" + arg0.getValue()); } } |