Java彻底 - WEB容器的侦听具体解释 ServletContextListener
2015-07-04 14:20
525 查看
WEB容器的侦听器ServletContextListener主要用于监测容器启动和 当破坏需要做一些操作,听众将能够使用此做。
ServletContextListener在Spring开始,然后再开始。
们实现一个简单的监听器,须要继承接口ServletContextListener:
ServletContextListener 实现两个接口,一个是容器启动的时候,一个是容器销毁的时候:
在web.xml中的配置:
容器启动后,会在容器启动的日志中看到:
ServletContextListener在Spring开始,然后再开始。
们实现一个简单的监听器,须要继承接口ServletContextListener:
* 一个測试的监听器样例 * @author zhuli * @date 2014-7-26 */ public class TestContextLister implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { System.out.println("==============================容器装载"); } @Override public void contextDestroyed(ServletContextEvent sce) { System.out.println("==============================容器销毁"); } }
ServletContextListener 实现两个接口,一个是容器启动的时候,一个是容器销毁的时候:
public interface ServletContextListener extends EventListener { /** ** Notification that the web application initialization ** process is starting. ** All ServletContextListeners are notified of context ** initialization before any filter or servlet in the web ** application is initialized. */ public void contextInitialized ( ServletContextEvent sce ); /** ** Notification that the servlet context is about to be shut down. ** All servlets and filters have been destroy()ed before any ** ServletContextListeners are notified of context ** destruction. */ public void contextDestroyed ( ServletContextEvent sce ); }
在web.xml中的配置:
<listener> <listener-class>com.xxx.controller.web.TestContextLister</listener-class> </listener>
容器启动后,会在容器启动的日志中看到:
==============================容器装载 2014-07-26 08:54:01.302:INFO:/:Initializing Spring FrameworkServlet 'apiServlet'
相关文章推荐
- 毫秒转换 成日期 相互转换
- java正则表达式大全
- java图片高质量压缩
- spring组件<context:component-scan>详解
- 使用Eclipse-Maven-git做Java开发(3)--Eclipse的安装和配置
- JAVA解析逻辑表达
- JAVA JSON 开发记录
- 2015070407 - EffactiveJava笔记 - 第59条 避免不必要地使用受检异常
- java 中的 aes 加密算法
- JAVA中使用FTPClient上传下载
- 学会JAVA可变长度的参数(Varargs)
- Java并发的四种风味:Thread、Executor、ForkJoin和Actor
- java总结(之八)--并发
- Java编程思想学习笔记——访问权限修饰词
- 2015070406 - EffactiveJava笔记 - 第58条 异常使用原则
- 将Eclipse中的项目迁移到Android Studio中的方法
- JAVA-1-学习历程1:基础知识1
- eclipse 配置-插件安装
- Eclipse - 快捷键的设置
- Java中SimpleDateFormat用法详解