Listeners induction

**

Monitor

**

针对三个tomcat的域对象
1 ServletContextListener
	两个方法 
		(1)服务器启动时创建ServletContext对象时执行此方法   : 
				用ServletContextEvent 获取ServletContext对象 进而来获取上下文对象 可以管理项目的上下文路径 (将上下文路径放到ServletContext域中)
		(2)服务器停止时或卸载项目时 ServletContext对象被销毁的时候执行此方法
	1实现 ServletContextListener
	2web.xml中配置 <listener><listener-class>你的监听器的全类名</listener-class></listener>
	使用场景:
		在服务器启动时建立数据库表结构,初始化数据库
		在服务器启动时,将数据库常量数据加载到内存,提供访问效率
		在服务器启动时,获取项目上下文路径,存放到application域,给页面使用
		存放计数器,计算在线用户数

     javax.servlet.ServletContextAttributeListener 
     监听ServletContext对象的属性的变化:添加,覆盖,删除 

2 HttpSessionListener
	监听HttpSession对象的创建和销毁 
  javax.servlet.http.HttpSessionAttributeListener 
 监听HttpSession对象的属性变化:添加,覆盖,删除 
 
3 ServletRequestListener
  监听HttpServletRequest对象的创建和销毁 
   javax.servlet.ServletRequestAttributeListener 
   监听HttpServletRequest对象的属性变化:添加,覆盖,删除 
 
 
Published 63 original articles · won praise 44 · views 6260

Guess you like

Origin blog.csdn.net/weixin_40695328/article/details/92389177