【JavaEE企业应用实战学习记录】MyGetAttributeListener

 1 package sanglp.servlet;
 2
 3 import javax.servlet.ServletContext;
 4 import javax.servlet.ServletContextAttributeEvent;
 5 import javax.servlet.ServletContextAttributeListener;
 6 import javax.servlet.annotation.WebListener;
 7
 8 /**
 9  * Created by Administrator on 2016/10/5.
10  * 监听ServletContext范围内属性改变的Listener
11  */
12 @WebListener
13 public class MyServletContextAttributeListener implements ServletContextAttributeListener {
14
15     @Override
16     public void attributeAdded(ServletContextAttributeEvent servletContextAttributeEvent) {
17         ServletContext application=servletContextAttributeEvent.getServletContext();
18         //获取添加的属性名和属性值
19         String name=servletContextAttributeEvent.getName();
20         Object value=servletContextAttributeEvent.getValue();
21         System.out.println(application+"范围内添加了"+name+"值为"+value+"的属性");
22
23
24     }
25
26     @Override
27     public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
28         ServletContext application=servletContextAttributeEvent.getServletContext();
29         //获取添加的属性名和属性值
30         String name=servletContextAttributeEvent.getName();
31         Object value=servletContextAttributeEvent.getValue();
32         System.out.println(application+"范围内删除了"+name+"值为"+value+"的属性");
33     }
34
35
36     @Override
37     public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {
38         ServletContext application=servletContextAttributeEvent.getServletContext();
39         //获取添加的属性名和属性值
40         String name=servletContextAttributeEvent.getName();
41         Object value=servletContextAttributeEvent.getValue();
42         System.out.println(application+"范围内替换了"+name+"值为"+value+"的属性");
43
44     }
45 }
时间: 2024-10-13 02:32:01

【JavaEE企业应用实战学习记录】MyGetAttributeListener的相关文章

【JavaEE企业应用实战学习记录】optiontransferselect实现两个列表选择框

1 <%@ page contentType="text/html; charset=GBK" language="java"%> 2 <%@taglib prefix="s" uri="/struts-tags"%> 3 <html> 4 <head> 5 <meta http-equiv="Content-Type" content="te

【JavaEE企业应用实战学习记录】Filter

1 package sanglp.servlet; 2 3 import javax.servlet.*; 4 import javax.servlet.annotation.WebFilter; 5 import javax.servlet.http.HttpServletRequest; 6 import java.io.IOException; 7 8 /** 9 * Created by Administrator on 2016/10/5. 10 */ 11 @WebFilter(fi

【JavaEE企业应用实战学习记录】struts配置文件详细解析

1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <!DOCTYPE struts PUBLIC 4 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" 5 "http://struts.apache.org/dtds/struts-2.3.dtd"> 6 7 <!--strut

【JavaEE企业应用实战学习记录】requestListener

1 package sanglp.servlet; 2 3 import javax.servlet.*; 4 import javax.servlet.annotation.WebListener; 5 import javax.servlet.http.HttpServletRequest; 6 7 /** 8 * Created by Administrator on 2016/10/5. 9 */ 10 @WebListener 11 public class RequestListen

【JavaEE企业应用实战学习记录】getConnListener

Listener:当Web应用在Web容器中运行时,Web应用内部会不断地发生各种事件,如Web应用被启动.Web应用被停止,用户Session开始,用户session结束.用户请求到达等,这些对Web事件对开发者是透明的. ServletAPI提供了大量的监听器来监听Web应用的内部事件,从而允许当Web内部事件发生时回调事件监听器内的方法. 使用步骤:定义Listener实现类 通过Annotation或在web.xml文件中配置Listener. 常用Listener类: ServletC

【JavaEE企业应用实战学习记录】authorityFilter

1 package sanglp.servlet; 2 3 import javax.servlet.*; 4 import javax.servlet.annotation.WebFilter; 5 import javax.servlet.annotation.WebInitParam; 6 import javax.servlet.http.HttpServletRequest; 7 import javax.servlet.http.HttpSession; 8 import java.

【JavaEE企业应用实战学习记录】struts国际化

1 <%-- 2 Created by IntelliJ IDEA. 3 User: Administrator 4 Date: 2016/10/6 5 Time: 16:26 6 To change this template use File | Settings | File Templates. 7 --%> 8 <%@ page contentType="text/html;charset=UTF-8" language="java" %

【JavaEE企业应用实战学习记录】struts2登录

1 <%-- login.jsp 2 Created by IntelliJ IDEA. 3 User: Administrator 4 Date: 2016/10/6 5 Time: 16:26 6 To change this template use File | Settings | File Templates. 7 --%> 8 <%@ page contentType="text/html;charset=UTF-8" language="ja

【JavaEE企业应用实战学习记录】sessionListener

1 package sanglp.servlet; 2 3 4 import javax.servlet.ServletContext; 5 import javax.servlet.annotation.WebListener; 6 import javax.servlet.http.HttpSession; 7 import javax.servlet.http.HttpSessionEvent; 8 import java.util.Hashtable; 9 import java.uti