myattributelistener.java

来自「JavaWeb高级特性书中源代码」· Java 代码 · 共 56 行

JAVA
56
字号
package org.it315.listener;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
public class MyAttributeListener implements ServletContextAttributeListener,
		HttpSessionAttributeListener, ServletRequestAttributeListener 
{
	public void attributeAdded(ServletContextAttributeEvent scae) 
	{
		System.out.println("servletContext对象中增加了一个名为" + 
			scae.getName() + "的属性,该属性值为" + scae.getValue());
	}
	public void attributeRemoved(ServletContextAttributeEvent scae) 
	{
		System.out.println("servletContext对象中的" + 
			scae.getName() + "属性被删除了");
	}
	public void attributeReplaced(ServletContextAttributeEvent scae) 
	{
        System.out.println("servletContext对象中" + scae.getName() + 
			"的属性值被替换成了" + scae.getValue());
	}
	public void attributeAdded(HttpSessionBindingEvent hbe)
	{
		System.out.println("httpSession对象中增加了一个名为" + 
			hbe.getName() + "的属性,该属性值为" + hbe.getValue());
	}
	public void attributeRemoved(HttpSessionBindingEvent hbe)
	{
		System.out.println("httpSession对象中的" + hbe.getName()
				+ "属性被删除了");
	}
	public void attributeReplaced(HttpSessionBindingEvent hbe) 
	{
		System.out.println("httpSession对象中" + hbe.getName() + 
			"的属性值被替换成了" + hbe.getValue());
	}
	public void attributeAdded(ServletRequestAttributeEvent srae) 
	{
		System.out.println("servletRequest对象中增加了一个名为" + 
			srae.getName() + "的属性,该属性值为" + srae.getValue());
	}
	public void attributeRemoved(ServletRequestAttributeEvent srae) 
	{
		System.out.println("servletRequest对象中的" + srae.getName()
				+ "属性被删除了");
	}
	public void attributeReplaced(ServletRequestAttributeEvent srae) 
	{
		System.out.println("servletRequest对象中" + srae.getName() + 
			"的属性值被替换成了" + srae.getValue());
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?