对application内置对象的监听器

ServletContextAttributeListener

该类监听对ServletContext属性的操作,比如,增加/删除/修改。

ServletContextListener

该类监听application内置对象的声明周期。

  • 创建ServletContext时,激发contextInitialized(ServletContextEvent sce)方法;
  • 销毁ServletContext时,激发contextDestroyed(ServletContextEvent sce)方法。

实现对application对象的监听

  1. 新建一个类实现ServletContextAttributeListener接口或者ServletContextListener类。
  2. 重写被继承类的方法。
  3. 在web.xml中注册该监听器。

你可能感兴趣的:(对application内置对象的监听器)