⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servletcontextdemo.java

📁 这是用Java写的一个监听器的代码
💻 JAVA
字号:
package cn.mldn.lxh.listener ;

import javax.servlet.* ;

public class ServletContextDemo
	implements ServletContextListener,ServletContextAttributeListener
{
	private ServletContext application = null ;
	// 实现方法
	public void contextInitialized(ServletContextEvent sce)
	{
		this.application = sce.getServletContext() ;
		System.out.println("** 上下文初始化 ...") ;
		System.out.println("** 当前虚拟目录的绝对路径:"+this.application.getRealPath("/")) ;
	}
	public void contextDestroyed(ServletContextEvent sce)
	{
		System.out.println("** 上下文销毁 ...") ;
	}

	public void attributeAdded(ServletContextAttributeEvent scab)
	{
		System.out.println("** 增加属性:"+scab.getName()+" --> "+scab.getValue()) ;
	}
	public void attributeRemoved(ServletContextAttributeEvent scab)
	{
		System.out.println("** 删除属性:"+scab.getName()+" --> "+scab.getValue()) ;
	}
	public void attributeReplaced(ServletContextAttributeEvent scab)
	{
		System.out.println("** 替换属性:"+scab.getName()+" --> "+scab.getValue()) ;
	}
};

/*
  <listener>
	<listener-class>cn.mldn.lxh.listener.ServletContextDemo</listener-class>
  </listener>
*/

⌨️ 快捷键说明

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