前言:在web应用中,有时候你想在web应用程序启动或关闭的时候执行一些任务,或者你想见他Session的创建和关闭等你就可以通过**来实现。那么Servlet来8个监视器接口,下面一一讲解一下。1:ServletContextListener和ServletContextAt ...
前言:在web应用中,有时候你想在web应用程序启动或关闭的时候执行一些任务,或者你想见他Session的创建和关闭等你就可以通过**来实现。那么Servlet来8个监视器接口,下面一一讲解一下。
1:ServletContextListener和ServletContextAttributeListener
1.1:ServletContextListener主要用于容器的启动和关闭时候进行监听。有2个方法分别用于监听容器启动和关闭。比喻我们在容器启动的时候做数据库连接的初始化。容器关闭时候可以通知从来启动另一个容器保证应用程序的稳定运行
代码如下
public class MyServletContextListener implements ServletContextListener{ public void contextInitialized(ServletContextEvent sce) { System.out.println("Servlet上下文对象开始进行初始化"); } public void contextDestroyed(ServletContextEvent sce) { System.out.println("Servlet上下文对象开始销毁"); }}
原标题:2016年8月18日 javaweb回顾第十二篇监听器
关键词:JAVA
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。