Jsp Servlet常用 Listener的分类
2009-12-06 20:57
393 查看
Servlet 监听器用于监听一些重要事件的发生,监听器对象在事情发生前、发生后可以做一些必要的处理。
目前 Servlet2.4 和 JSP2.0 常用的有7个监听器接口,分为3类:
1. Servlet上下文进行监听(Application级):
用于监听 ServletContext 对象的创建和删除以及属性的添加、删除和修改等操作,该监听器需要用到如下两个接口类:
(1) ServletContextAttributeListener:监听对 ServletContext 属性的操作,比如增加、删除、修改
attributeAdded(ServletContextAttributeEvent e) 添加属性时调用
attributeReplaced(ServletContextAttributeEvent e) 修改属性时调用
attributeRemoved(ServletContextAttributeEvent e) 删除属性时调用
(2) ServletContextListener:监听对 ServletContext 对象的创建和删除
contextInitialized(ServletContextEvent sce) 初始化时调用
contextDestroyed(ServletContextEvent sce) 销毁时调用,即当服务器重新加载时调用
2. 监听HTTP会话(Session级):
用于监听 HTTP 会话活动情况和 HTTP 会话中的属性设置情况,也可以监听 HTTP 会话的 active 和 passivate 情况等,该监听器需要用到如下多个接口类:
(1) HttpSessionListener:监听 HttpSession 的操作
sessionCreate(HttpSessionEvent se) 初始化时调用;
sessionDestroyed(httpSessionEvent se) 销毁时调用,即当用户注销时调用
(2) HttpSessionActivationListener:用于监听 HTTP 会话的 active 和 passivate 情况
(3) HttpSessionAttributeListener:监听 HttpSession 中的属性操作
attributeAdded(HttpSessionBindingEvent se) 添加属性时调用
attributeRemoved(HttpSessionBindingEvent se) 删除属性时调用
attributeReplaced(HttpSessionBindingEvent se) 修改属性时调用
3. 对客户端请求进行监听(Requst级):
用于对客户端的请求进行监听是在 Servlet2.4 规范中新添加的一项新技术,使用的接口如下:
(1) ServletRequestListener 接口类
requestDestroyed(ServletRequestEvent e) 对销毁客户端进行监听,即当执行 request.removeAttribute("xxx") 时调用
requestInitialized(ServletRequestEvent e) 对实现客户端的请求进行监听
(2) ServletRequestAttributeListener 接口类
attributeAdded(ServletRequestAttributeEvent e) 对属性添加进行监听
attributeRemoved(ServletRequestAttributeEvent e) 对属性删除进行监听
attributeReplaced(ServletRequestAttributeEvent e) 对属性替换进行监听
目前 Servlet2.4 和 JSP2.0 常用的有7个监听器接口,分为3类:
1. Servlet上下文进行监听(Application级):
用于监听 ServletContext 对象的创建和删除以及属性的添加、删除和修改等操作,该监听器需要用到如下两个接口类:
(1) ServletContextAttributeListener:监听对 ServletContext 属性的操作,比如增加、删除、修改
attributeAdded(ServletContextAttributeEvent e) 添加属性时调用
attributeReplaced(ServletContextAttributeEvent e) 修改属性时调用
attributeRemoved(ServletContextAttributeEvent e) 删除属性时调用
(2) ServletContextListener:监听对 ServletContext 对象的创建和删除
contextInitialized(ServletContextEvent sce) 初始化时调用
contextDestroyed(ServletContextEvent sce) 销毁时调用,即当服务器重新加载时调用
2. 监听HTTP会话(Session级):
用于监听 HTTP 会话活动情况和 HTTP 会话中的属性设置情况,也可以监听 HTTP 会话的 active 和 passivate 情况等,该监听器需要用到如下多个接口类:
(1) HttpSessionListener:监听 HttpSession 的操作
sessionCreate(HttpSessionEvent se) 初始化时调用;
sessionDestroyed(httpSessionEvent se) 销毁时调用,即当用户注销时调用
(2) HttpSessionActivationListener:用于监听 HTTP 会话的 active 和 passivate 情况
(3) HttpSessionAttributeListener:监听 HttpSession 中的属性操作
attributeAdded(HttpSessionBindingEvent se) 添加属性时调用
attributeRemoved(HttpSessionBindingEvent se) 删除属性时调用
attributeReplaced(HttpSessionBindingEvent se) 修改属性时调用
3. 对客户端请求进行监听(Requst级):
用于对客户端的请求进行监听是在 Servlet2.4 规范中新添加的一项新技术,使用的接口如下:
(1) ServletRequestListener 接口类
requestDestroyed(ServletRequestEvent e) 对销毁客户端进行监听,即当执行 request.removeAttribute("xxx") 时调用
requestInitialized(ServletRequestEvent e) 对实现客户端的请求进行监听
(2) ServletRequestAttributeListener 接口类
attributeAdded(ServletRequestAttributeEvent e) 对属性添加进行监听
attributeRemoved(ServletRequestAttributeEvent e) 对属性删除进行监听
attributeReplaced(ServletRequestAttributeEvent e) 对属性替换进行监听
相关文章推荐
- Jsp Servlet常用 Listener的分类
- Jsp Servlet常用 Listener的分类
- jsp页面到servlet常用传值方法
- J2EE初级学习项目——JSP+Servlet+JavaBean开发模式+Filter+(Listener)+Jdbc的用户登录注册系统
- Servlet & JSP - Listener
- servlet,jsp,listener,filter作用详解
- Servlet JSP Tutorial -- 1.5 ServletContextListener Servlet Listener Example
- jsp和servlet中常用的几句。
- 解决Get和Post请求中中文乱码问题 (2013-01-26 23:59:39)转载▼ 标签: javaee it 分类: JavaEE 对于Post请求,只需在Servlet或者jsp中写入如下
- Jsp/Servlet中的Listener事件监听
- JAVA_WEB项目(结合Servlet+jsp+ckEditor编辑器+jquery easyui技术)实现新闻发布管理系统第四篇:前台首页,新闻分类(体育新闻,科技新闻等),新闻列表分页的实现
- JSP/Servlet-----12、Listener
- 【Listener】利用监听器Listener以MVC的思想通过JSP+Servlet+JDBC完成在线用户列表的输出
- JSP/Servlet中的Listener
- jsp session的创建和销毁javax.servlet.http.HttpSessionListener 监听
- jsp中通过部署标识符方式配置filter、listener、servlet
- 《Head First Servlets & JSP》-6-会话管理-listener etc. demo
- ###Jsp+Servlet购物商城day02.1: 页面加载完,导航栏显示分类信息。(在公共页面head.jsp)
- 【Head First Servlets and JSP】笔记14:session再探 & Listener示例
- JSP之监听器Listener(一)————————ServletContextListener