javax.servlet.ServletContextListener
2016-07-16 12:55
411 查看
javax.servlet.ServletContextListener 接口
http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html父接口
注意,此接口是在 java.util 包下。文档说明此接口:是所有事件监听器接口必须 extend 的标记接口。package java.util; /** * A tagging interface that all event listener interfaces must extend. * @since JDK1.1 */ public interface EventListener { }
接口原型
public interface ServletContextListener extends EventListener { public void contextInitialized(ServletContextEvent sce); public void contextDestroyed(ServletContextEvent sce); }
接口文档
英文文档
Interface for receiving notification events about ServletContext lifecycle changes. In order to receive these notification events, the implementation class must be either declared in the deployment descriptor of the web application, annotated with javax.servlet.annotation.WebListener, or registered via one of the addListener methods defined on ServletContext. Implementations of this interface are invoked at their contextInitialized method in the order in which they have been declared, and at their contextDestroyed method in reverse order. Since: Servlet 2.3 See Also: ServletContextEvent
中文翻译
(ServletContextListener 是)一个接收 ServletContext 生命周期通知事件的 Interface。 为了接收这些通知事件,实现类必须被 javax.servlet.annotation.WebListener 注解并声明在 Web 部署描述(文件)中, 或被 ServletContext 中定义的其中一个 addListener 方法注册。 此接口的实现类的 contextInitialized 方法会被按他们的声明顺序调用,contextDestroyed 方法则按相反的顺序。 Since: Servlet 2.3 See Also: ServletContextEvent
contextInitialized 方法文档
英文文档
public void contextInitialized(ServletContextEvent sce);Receives notification that the web application initialization process is starting. All ServletContextListeners are notified of context initialization before any filters or servlets in the web application are initialized. Parameters: sce the ServletContextEvent containing the ServletContext that is being initialized
中文翻译
接收 Web 应用初始化程序启动的通知。 所有 ServletContextListeners 会在 Web 应用中所有的 filters or servlets 被初始化之前被通知。 Parameters: sce:包含当前正在被初始化的 ServletContext 的 ServletContextEvent。
contextDestroyed 方法文档
英文文档
public void contextDestroyed(ServletContextEvent sce);Receives notification that the ServletContext is about to be shut down. All servlets and filters will have been destroyed before any ServletContextListeners are notified of context destruction. Parameters: sce the ServletContextEvent containing the ServletContext that is being destroyed
中文翻译
接收 Web 应用初始化程序将被关闭的通知。 所有 ServletContextListeners 会在所有 servlets and filters 被销毁之后,被通知上下文销毁。 Parameters: sce:包含当前正在被销毁的 ServletContext 的 ServletContextEvent。
总结
ServletContextListener 是接收 ServletContext 生命周期通知事件的接口。可以确保的是:contextInitialized 会在所有 filters 和 servlets 被初始化之前被调用。
可以确保的是:contextDestroyed 会在所有 filters 和 servlets 被销毁之后被调用。
contextInitialized 和 contextDestroyed 都提供 ServletContextEvent 参数,通过该参数可以访问到 ServletContext 上下文。
ServletContextListener 的 contextInitialized 方法会按照 ServletContextListener 声明顺序被 Web 容器调用,
而 contextDestroyed 则相反。
相关文章推荐
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- Struts2国际化——完整实例代码
- javaWeb项目下加载dll文件(转载)
- Spring MVC中使用Swagger生成API文档和完整项目示例Demo,swagger-server-api
- Spring MVC中使用Swagger生成API文档和完整项目示例Demo,swagger-server-api
- Spring MVC中使用Swagger生成API文档和完整项目示例Demo,swagger-server-api
- Spring MVC中使用Swagger生成API文档和完整项目示例Demo,swagger-server-api
- java启动操作系统上安装的应用程序
- Java基本概念(2)J2EE里面的2是什么意思
- java环境变量完整版
- J2EE进阶(三)struts2 <s:action>标签的用法
- J2EE进阶(三)struts2 <s:action>标签的用法
- Java Annotation概述
- JAVA加密类型和算法名称
- Java 8中一些常用的全新的函数式接口
- 从内存角度解析Java字符编码
- Spring IOC注入(三)自动注入
- J2EE进阶(五)Spring在web.xml中的配置
- J2EE进阶(五)Spring在web.xml中的配置
- Springmvc