Listener监听器

来源:互联网 发布:chrome json 插件 编辑:程序博客网 时间:2024/05/28 22:11

Listener,事件有很多,每种事件都有对应的特定Listener去处理。
但是整体来说,Listener用的不多,我们只学习两个Listener

实现了ServletContextListener,HttpSessionActivationListener。这个接口。

package com.rupeng.web;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;public class MyServletContextListener implements ServletContextListener {    public void contextInitialized(ServletContextEvent sce) {        //ServletContext创建的时候,此方法就会自动被调用        System.out.println("servletContext对象创建了");      }    public void contextDestroyed(ServletContextEvent sce) {        //当 ServletContext被销毁的时候,tomocat服务就会自动调用此方法,相当于时间注册了时间处理函数        System.out.println("ServletContext对象被销毁了");    }}//当然记得在web.xml中配置路径listener  <!-- 配置listener -->  <listener>  <listener-class>com.rupeng.web.MyServletContextListener</listener-class>  </listener>
原创粉丝点击