`
king_tt
  • 浏览: 2300720 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Java-ServletContextEvent-ServletContextAttributeEvent

 
阅读更多
//这是一个事件类用来通知一个web 应用的servlet 上下文的改变
public class ServletContextEvent extends java.util.EventObject { 

	/** Construct a ServletContextEvent from the given context.
	 *
	 * @param source - the ServletContext that is sending the event.
	 */
    public ServletContextEvent(ServletContext source) {
	super(source);
    }
    
	/**
	 * Return the ServletContext that changed.
	 *
	 * @return the ServletContext that sent the event.
	 */
    public ServletContext getServletContext () { 
	return (ServletContext) super.getSource();
    }
    
}

public class ServletContextAttributeEvent extends ServletContextEvent { 
	private String name;
	private Object value;

	/** Construct a ServletContextAttributeEvent from the given context for the
	** given attribute name and attribute value. 
	*/
	//构造一个servlet上下文属性事件
	public ServletContextAttributeEvent(ServletContext source, String name, Object value) {
	    super(source);
	    this.name = name;
	    this.value = value;
	}
	
	/**
	* Return the name of the attribute that changed on the ServletContext.
	*
	*/
	
	public String getName() {
		return this.name;
	}
	
	/**
	* Returns the value of the attribute that has been added, removed, or replaced.
	* If the attribute was added, this is the value of the attribute. If the attribute was
	* removed, this is the value of the removed attribute. If the attribute was replaced, this
	* is the old value of the attribute.
	*
	*/
	
	public Object getValue() {
	    return this.value;   
	}
}

分享到:
评论

相关推荐

    Java的监听器种类

    ### Java的监听器种类 Java中的监听器是一种特殊类型的对象,它们主要负责监听特定的事件并在这些事件发生时执行相应的动作。监听器广泛应用于多种场景,尤其是在Servlet容器中,监听器能够帮助开发者更加灵活地...

    servlet2.4doc

    Overrides the standard java.lang.Object.clone method to return a copy of this cookie. containsHeader(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of ...

    Java的监听器种类.pdf

    在Java的Web开发中,监听器(Listener)是一种强大的工具,它允许程序员对特定事件进行响应,而无需直接干预应用程序的流程。监听器主要用于监控Servlet容器中的各种事件,例如Servlet上下文的创建和销毁,HTTP会话...

    java listener监听器教程及实例

    - **接收事件**:`ServletContextEvent` - **触发场景**:当Web应用被部署到服务器时,容器会调用`contextInitialized()`方法;当Web应用从服务器上卸载时,容器会调用`contextDestroyed()`方法。 ##### 2. **...

    JAVA J2EE 类库文档

    ServletContextAttributeEvent ServletContextAttributeListener ServletContextEvent ServletContextListener ServletException ServletInputStream ServletOutputStream ServletRequest ...

    ServletListener大全

    在Java Web开发中,`ServletListener`是一类特殊的设计模式,主要用于监听容器中的事件。例如,当一个HTTP会话被创建或销毁时,或者当请求开始或结束时,这些监听器可以执行特定的操作。它们通过观察者设计模式实现...

    Servlet中的八大Listener

    - **事件对象**:`ServletContextAttributeEvent` - **作用**:用于监听ServletContext中的属性变化情况,例如添加新属性、替换现有属性或移除属性等。 3. **HttpSessionListener** - **事件方法**: - `...

    深入学习JavaWeb中监听器(Listener)的使用方法

    - 示例方法:`contextInitialized(ServletContextEvent sce)` 和 `contextDestroyed(ServletContextEvent sce)` 2. **会话级监听器(HttpSessionListener)** - 监听用户会话的创建和销毁事件。 - 实现接口:`...

    Servilet概述

    Servlet 是 Java Web 开发的基础理论,是许多框架的实现基础,掌握 Servlet 的用法非常必要。下面是关于 Servlet 的概述式讲解,包括 Servlet 的分类、用法、监听器、过滤器等。 Servlet 程序由 Servlet、Filter ...

    基于Listener监听器生命周期(详解)

    监听器(Listener)是Web开发中重要的组件之一,属于Java Servlet规范中的一部分。监听器主要作用是监听Web应用中对象的创建、销毁以及属性变化等事件,并能够对这些事件做出响应。以下将详细解析Listener监听器的...

Global site tag (gtag.js) - Google Analytics