26 ,srae.getName()
27 ,srae.getValue());
28 System.out.println(str);
29 }
30
31 @Override
32 public void attributeReplaced(ServletRequestAttributeEvent srae) {
33 String str =MessageFormat.format(
34 “ServletRequest域对象中替换了属性:{0}的值”
35 ,srae.getName());
36 System.out.println(str);
37 }
38
39 @Override
40 public void attributeAdded(HttpSessionBindingEvent se) {
41 String str =MessageFormat.format(
42 “HttpSession域对象中添加了属性:{0},属性值是:{1}”
43 ,se.getName()
44 ,se.getValue());
45 System.out.println(str);
46 }
47
48 @Override
49 public void attributeRemoved(HttpSessionBindingEvent se) {
50 String str =MessageFormat.format(
51 “HttpSession域对象中删除属性:{0},属性值是:{1}”
52 ,se.getName()
53 ,se.getValue());
54 System.out.println(str);
55 }
56
57 @Override
58 public void attributeReplaced(HttpSessionBindingEvent se) {
59 String str =MessageFormat.format(
60 “HttpSession域对象中替换了属性:{0}的值”
61 ,se.getName());
62 System.out.println(str);
63 }
64 }
在web.xml文件中注册监听器
1 2 MyRequestAndSessionAttributeListener监听器3 me.gacl.web.listener.MyRequestAndSessionAttributeListener4
编写RequestAndSessionAttributeListenerTest.jsp测试页面
1 <%@ page language=“java” pageEncoding=“UTF-8”%> 2 3 4 5
8 9 <%10 //往session域对象中添加属性
11 session.setAttribute(“aa”, “bb”);
12 //替换session域对象中aa属性的值
13 session.setAttribute(“aa”, “xx”);
14 //移除session域对象中aa属性
15 session.removeAttribute(“aa”);
16
17 //往request域对象中添加属性
18 request.setAttribute(“aa”, “bb”);
19 //替换request域对象中aa属性的值