JavaWeb之监听器简要知识

监听器的任务:

监听变化域的变化:
request(HttpServletRequest)
session(HttpSession)
application(ServletContext)

监听器可以做的应用:

统计在线人数
web启动时做初始化工作

建立监听器的步骤:
1.继承相关的类:

ServletContextListener监听ServletContext对象
ServletContextAttributeListener监听对ServletContext属性

HttpSessionListener监听Session对象
HttpSessionAttributeListener监听Session中的属性

ServletRequestListener监听Request对象
ServletRequestAttributeListener监听Requset中的属性

2.实现各个类中需要实现的方法
监听对象:创建和销毁两个方法
监听属性:属性添加、移除、修改三个方法

3.在web.xml标识监听器的存在就可以了(一般ide会自动完成)

发布了68 篇原创文章 · 获赞 12 · 访问量 5216

猜你喜欢

转载自blog.csdn.net/qq_40963076/article/details/104444134