ServletContextAttributeListener, HttpSessionAttributeListener 和ServletRequestAttributeListener,这三个接口中都定义了三个方法来处理被监听对象中的属性的增加,删除和替换的事件,同一个事件在这三个接口中对应的方法名称完全相同,只是接受的参数类型不同。
attributeAdded 方法:
1 public void attributeAdded(ServletContextAttributeEvent scae)
2 public void attributeReplaced(HttpSessionBindingEvent hsbe)
3 public void attributeRmoved(ServletRequestAttributeEvent srae)
attributeRemoved 方法
1 public void attributeRemoved(ServletContextAttributeEvent scae)
2 public void attributeRemoved (HttpSessionBindingEvent hsbe)
3 public void attributeRemoved (ServletRequestAttributeEvent srae)
attributeReplaced 方法
1 public void attributeReplaced(ServletContextAttributeEvent scae)
2 public void attributeReplaced (HttpSessionBindingEvent hsbe)
3 public void attributeReplaced (ServletRequestAttributeEvent srae)
<listener>
<listener-class>listener.MyServletContextAttributeListener</listener-class>
</listener>
public class MyServletContextAttributeListener implements ServletContextAttributeListener {
@Override
public void attributeAdded(ServletContextAttributeEvent scab) {
String str =MessageFormat.format(
"ServletContext域对象中添加了属性:{},属性值是:{}"
,scab.getName()
,scab.getValue());
System.out.println(str);
}
@Override
public void attributeRemoved(ServletContextAttributeEvent scab) {
String str =MessageFormat.format(
"ServletContext域对象中删除属性:{},属性值是:{}"
,scab.getName()
,scab.getValue());
System.out.println(str);
}
@Override
public void attributeReplaced(ServletContextAttributeEvent scab) {
String str =MessageFormat.format(
"ServletContext域对象中替换了属性:{}的值"
,scab.getName());
System.out.println(str);
}
}
jsp测试;
<%
//往application域对象中添加属性
application.setAttribute("name", "nick");
//替换application域对象中name属性的值
application.setAttribute("name", "gacl");
//移除application域对象中name属性
application.removeAttribute("name");
%>
ServletContextListener监听ServletContext域对象(application)中的属性值的变化情况。
同理对其他两个监听进行测试。
分享到:
相关推荐
JavaWeb课程设计---客户管理系统.pdf
Jsp-Order-online+javaweb 网上点餐项目Jsp-Order-online+javaweb 网上点餐项目Jsp-Order-online+javaweb 网上点餐项目Jsp-Order-online+javaweb 网上点餐项目Jsp-Order-online+javaweb 网上点餐项目Jsp-Order-on...
Listener监听器 JavaBean Servlet Jsp XML ...JAVA WEB开发技术 ...用于监听域对象属性增加和删除的事件监听器 用于监听绑定到HttpSession域中某个对象 状态的事件监听器 ServletContextListener接口 HttpS
JavaWeb学习资料---PDF格式,希望能够学习者提供帮助,文档中包含多个JavaWeb学习环节,循序渐渐地介绍了JavaWeb的相关知识
JavaWeb课程设计汇本---客户管理系统.doc
Javaweb图书管理系统--完整项目,整个项目完整打包。
利用新浪微博开放平台开发javaweb应用----用户授权.pdf
JavaWeb课程设计---客户管理系统方案.doc
利用新浪微博开放平台开发javaweb应用----用户授权参照.pdf
利用新浪微博开放平台开发javaweb应用----用户授权借鉴.pdf
自存-javaweb-ssm-spring-springboot-html-vanta.js
明日科技的javaweb典型模块宝典--打印模块,节省了开发时间
基于javaweb的课程设计--奶茶销售管理系统源码+数据库.zip 95分以上高分必过项目,下载即用无需修改,项目完整确保可以运行。 基于javaweb的课程设计--奶茶销售管理系统源码+数据库.zip 95分以上高分必过项目,...
JavaWeb开发Eclipse环境配置--史上最详细的教程,环境搭建,tocat配置,等
JavaWeb 入门级项目实战 -- 文章发布系统 原码
基于MVC的Javaweb项目-----简单的唱片管理销售平台 # 初学javaweb,制作简单唱片销售管理平台-附件资源
本学期javaWeb课程实验源码,本次实验是练习jsp内置对象的使用,包括登录注册以及验证共4个jsp页面,另外还有一个cookies的操作页面,具体教程可看本人博客
JavaWeb学习笔记,自己使用 ---------------------------------凑字数的小尾巴