学习java web中的listener
web.xml里的顺序为:context-param->listener->filter->servlet
监听器是需要新建一个类,然后按监听的对象继承:ServletContext、HttpSession、ServletRequest中的一个
监听ServletContext生命周期的Listener
//ServletContext lifecycle changes
public interface ServletContextListener extends EventListener { //initialized
public void contextInitialized(ServletContextEvent sce); //destroyed
public void contextDestroyed(ServletContextEvent sce);
}
监听ServletContext属性的Listener
public interface ServletContextAttributeListener extends EventListener {
/**
* Receives notification that an attribute has been added to the
* ServletContext.
*
* @param event the ServletContextAttributeEvent containing the
* ServletContext to which the attribute was added, along with the
* attribute name and value
*/
public void attributeAdded(ServletContextAttributeEvent event);
/**
* Receives notification that an attribute has been removed
* from the ServletContext.
*
* @param event the ServletContextAttributeEvent containing the
* ServletContext from which the attribute was removed, along with
* the attribute name and value
*/
public void attributeRemoved(ServletContextAttributeEvent event);
/*
* Receives notification that an attribute has been replaced
* in the ServletContext.
*
* @param event the ServletContextAttributeEvent containing the
* ServletContext in which the attribute was replaced, along with
* the attribute name and its old value
*/
public void attributeReplaced(ServletContextAttributeEvent event);
}
监听HttpSession生命周期的Listener
//about HttpSession lifecycle changes.
public interface HttpSessionListener extends EventListener { /**
* Receives notification that a session has been created.
*
* @param se the HttpSessionEvent containing the session
*/
public void sessionCreated(HttpSessionEvent se); /**
* Receives notification that a session is about to be invalidated.
*
* @param se the HttpSessionEvent containing the session
*/
public void sessionDestroyed(HttpSessionEvent se); }
监听HttpSession属性的Listener
public interface HttpSessionAttributeListener extends EventListener {
/**
* Receives notification that an attribute has been added to a
* session.
*
* @param event the HttpSessionBindingEvent containing the session
* and the name and value of the attribute that was added
*/
public void attributeAdded(HttpSessionBindingEvent event);
/**
* Receives notification that an attribute has been removed from a
* session.
*
* @param event the HttpSessionBindingEvent containing the session
* and the name and value of the attribute that was removed
*/
public void attributeRemoved(HttpSessionBindingEvent event);
/**
* Receives notification that an attribute has been replaced in a
* session.
*
* @param event the HttpSessionBindingEvent containing the session
* and the name and (old) value of the attribute that was replaced
*/
public void attributeReplaced(HttpSessionBindingEvent event);
}
监听ServletReques生命周期的tListener
public interface ServletRequestListener extends EventListener {
/**
* Receives notification that a ServletRequest is about to go out
* of scope of the web application.
*
* @param sre the ServletRequestEvent containing the ServletRequest
* and the ServletContext representing the web application
*/
public void requestDestroyed(ServletRequestEvent sre);
/**
* Receives notification that a ServletRequest is about to come
* into scope of the web application.
*
* @param sre the ServletRequestEvent containing the ServletRequest
* and the ServletContext representing the web application
*/
public void requestInitialized(ServletRequestEvent sre);
}
监听ServletReques属性的Listener
public interface ServletRequestAttributeListener extends EventListener {
/**
* Receives notification that an attribute has been added to the
* ServletRequest.
*
* @param srae the ServletRequestAttributeEvent containing the
* ServletRequest and the name and value of the attribute that was
* added
*/
public void attributeAdded(ServletRequestAttributeEvent srae);
/**
* Receives notification that an attribute has been removed from the
* ServletRequest.
*
* @param srae the ServletRequestAttributeEvent containing the
* ServletRequest and the name and value of the attribute that was
* removed
*/
public void attributeRemoved(ServletRequestAttributeEvent srae);
/**
* Receives notification that an attribute has been replaced on the
* ServletRequest.
*
* @param srae the ServletRequestAttributeEvent containing the
* ServletRequest and the name and (old) value of the attribute
* that was replaced
*/
public void attributeReplaced(ServletRequestAttributeEvent srae);
}
HttpSessionBindingListener:该接口有两个方法,valueBound和valueUnbound,实现该接口的对象要new以后放在session里。
HttpSessionActivationListener :实现了HttpSessionActivationListener接口的JavaBean对象可以感知自己被活化(反序列化)sessionDidActivate和钝化(序列化)sessionWillPassivate的事件
HttpSessionBindingListener和HttpSessionListener区别是前者要创建对象后放入session中,后者创建一次
学习java web中的listener的更多相关文章
- 疯狂学习java web
因工作需要,疯狂学习java web,只是这么多年一直从事C++开发,突然之间要接手同事的那么一大堆代码,真有无从下手的感觉,首先是要学习html,然后是js, 然后是jsp,当然还有各种框架,想想就 ...
- 零基础如何系统学习Java Web
零基础如何系统学习Java Web? 我来给你说一说 你要下决心,我要转行做开发,这样你才能学成. 你要会打字,我公司原来有一个程序员,打字都是两个手一指禅,身为程序员你一指禅怎么写出的代码,半个 ...
- Java Web 中 过滤器与拦截器的区别
过滤器,是在java web中,你传入的request,response提前过滤掉一些信息,或者提前设置一些参数,然后再传入servlet或者struts的 action进行业务逻辑,比如过滤掉非法u ...
- JAVA WEB 中的编码分析
JAVA WEB 中的编码分析 */--> pre.src {background-color: #292b2e; color: #b2b2b2;} pre.src {background-co ...
- Java web中常见编码乱码问题(一)
最近在看Java web中中文编码问题,特此记录下. 本文将会介绍常见编码方式和Java web中遇到中文乱码问题的常见解决方法: 一.常见编码方式: 1.ASCII 码 众所周知,这是最简单的编码. ...
- Java web中常见编码乱码问题(二)
根据上篇记录Java web中常见编码乱码问题(一), 接着记录乱码案例: 案例分析: 2.输出流写入内容或者输入流读取内容时乱码(内容中有中文) 原因分析: a. 如果是按字节写入或读取时乱码, ...
- 深入分析Java Web中的编码问题
编码问题一直困扰着我,每次遇到乱码或者编码问题,网上一查,问题解决了,但是实际的原理并没有搞懂,每次遇到,都是什么头疼. 决定彻彻底底的一次性解决编码问题. 1.为什么要编码 计算机的基本单元是字节, ...
- 解决java web中safari浏览器下载后文件中文乱码问题
解决java web中safari浏览器下载后文件中文乱码问题 String fileName = "测试文件.doc"; String userAgent = request.g ...
- Java Web 中使用ffmpeg实现视频转码、视频截图
Java Web 中使用ffmpeg实现视频转码.视频截图 转载自:[ http://www.cnblogs.com/dennisit/archive/2013/02/16/2913287.html ...
随机推荐
- APP开发者如何从应用程序中赚钱?
付费应用程序,这是应用程序最基本的赚钱方式之一,也是拥有巨大潜力的赚钱方式之一.但有一个问题开发者必须扪心自问,您的程序用户是否有一批粉丝级用户的认可,或对您应用程序品牌的认可 蝉大师APP推广工 ...
- 超全Altium Designer16 总结--Altium Designer
原址:http://blog.csdn.net/qq_29350001/article/details/52199356 以前是使用DXP2004来画图的,后来转行.想来已经有一年半的时间没有画过了. ...
- Minimal Power of Prime
题目链接 题意:输入n,求所有质因子幂的最小值.n奇大无比. 思路:先对n所有n开五次方根的质因子约完,然后如果没有除尽的话,因子最多也就4个了,所以幂数大于1的情况有p1^4,p1^3, p1^2 ...
- [CSP-S模拟测试]:platform(后缀数组+二分+线段树)
题目传送门 题目描述 走过奈何桥有一个名叫望乡台的土台,望乡台有个名曰孟婆的老妇人在卖孟婆汤.一生爱恨情仇,一世浮沉得失,都可以随这碗孟婆汤遗忘得干干净净.现在有$n$碗孟婆汤摆成一排,汤的品种不超过 ...
- junit中配置log4j日志
在对项目单元测试的时候,有时候会使用log4j来打印日志,这个时候需要对log4j进行配置. 声明和继承SpringJUnit4ClassRunner类,在这个类中对log4j的配置文件进行加载. p ...
- 用 Flask 来写个轻博客 (30) — 使用 Flask-Admin 增强文章管理功能
Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 扩展阅读 实现文章管理功能 实现效果 前文列表 用 Flask 来写个 ...
- "New page after" by code
Hi. There is a method for starting of the new page in the EngineV2: Engine.NewPage(); You can call i ...
- 面试题:Nginx负载均衡的算法怎么实现的?为什么要做动静分离?
面试题 Nginx负载均衡的算法怎么实现的?Nginx 有哪些负载均衡策略?Nginx为什么要做动静分离? 面试官心理剖析 主要是看应聘人员对Nginx的基本原理是否熟悉,需要应聘人员能够根据实际业务 ...
- Linux(Ubuntu)常用命令(四)
权限修改: 先知: u user 表示该文件的所有者 g group 表示与该文件的所有者属于同一组( group )者,即用户组 o other 表示其他以外的人 a all 表示这三者皆是 r r ...
- spring boot 尚桂谷学习笔记07 嵌入式容器 ---Web
------配置嵌入式servlet容器------ springboot 默认使用的是嵌入的Servlet(tomcat)容器 问题? 1)如何定制修改Servlet容器的相关配置: 1.修改和se ...