目录
1.监听器Listener
1.1.监听器概述
在JavaWeb被监听的事件源为:ServletContext、HttpSession、ServletRequest,即三大域对象。
监听域对象“创建”与“销毁”的监听器;
监听域对象“操作域属性”的监听器;
监听HttpSession的监听器。
1.2.ServletContextListener
ServletContextListener:Tomcat启动和关闭时调用下面两个方法:
public void contextInitialized(ServletContextEvent evt):ServletContext对象被创建后调用;
public void contextDestroyed(ServletContextEvent evt):ServletContext对象被销毁前调用;
1.3.HttpSessionListener
HttpSessionListener:开始会话和结束会话时调用下面两个方法
public void sessionCreated(HttpSessionEvent evt):HttpSession对象被创建后调用;
public void sessionDestroyed(HttpSessionEvent evt):HttpSession对象被销毁前调用;