Implementations of this interface recieve notifications about changes to the servlet context of the web application they are part of. To recieve notification events, the implementation class must be configured in the deployment descriptor for the web application.
——这个事件类作为Web应用服务的一部分,处理Web应用的 servlet上下文(context)的变化的通知。这可以解释为,好像有个人在服务器旁不断地通知我们服务器在发生什么事件。那当然需要监听者了。因 此,在通知上下文(context)初始化和销毁的时候,ServletContextListner非常有用。
A ServletRequestListener can be implemented by the developer interested in being notified of requests coming in and out of scope in a web component. A request is defined as coming into scope when it is about to enter the first servlet or filter in each web application, as going out of scope when it exits the last servlet or the first filter in the chain.
——
注意:
<link href="...">
<script src="...">
<jsp:include ...>
这种代码均会出发ServletRequestListener。
Implementations of this interface may are notified of changes to the list of active sessions in a web application. To recieve notification events, the implementation class must be configured in the deployment descriptor for the web application.
——当一个浏览器第一次访问网站的时候,J2EE应用服务器会新建一个 HttpSession对象,并触发HttpSession创建事件,如果注册了HttpSessionListener事件监听器,则会调用 HttpSessionListener事件监听器的sessionCreated方法。相反,当这个浏览器访问结束超时的时候,J2EE应用服务器会销 毁相应的HttpSession对象,触发HttpSession销毁事件,同时调用所注册HttpSessionListener事件监听器的 sessionDestroyed方法。
如果同时配置了ServletContextListener,HttpSessionListener,ServletRequestListener,容器启动时
会 先调用ServletContextListener的contextInitialized方法。然后当客户端有请求到来,会先调用 ServletRequestListener的requestInitialized方法,然后再调用HttpSessionListener的 sessionCreated方法,如果发生上面所说的页面链接了其它文件的情况,则会再次触发ServletRequestListener的 requestInitialized方法。