javaWeb监听器

优先级顺序:

监听器>过滤器>servlet

web.xml配置监听器信息:

<listener>
    <listener-class>com.itheima.attribute.MyServletContextAttributeListener</listener-class>
</listener>

session配置信息

<session-config>
	<session-timeout>30</session-timeout>
	<cookie-config>
		<name>JSESSIONID</name>
		<domain>example.org</domain>
		<path>/shop</path>
		<comment>
			<!-- some information -->
		</comment>
		<http-only>true</http-only>
		<secure>false</secure>
		<max-age>1800</max-age>
	</cookie-config>
	<tracking-mode>COOKIE</tracking-mode>
	<tracking-mode>URL</tracking-mode>
	<tracking-mode>SSL</tracking-mode>
</session-config>

web监听器可以监听客户端的请求和服务端的操作。

监听对象:

1.ServletContext(application:上下文对象,一个web应用对应一个application)

2.session:对应会话,关闭web应用和浏览器时候清空session,session超时

3.request

作用:监听监听对象的创建和销毁,以及监听对象属性的变化发生修改的事件,在监听前和监听后进行一些处理

操作域属性的监听器(3个)
    当对域属性进行增、删、改时,执行的监听器一共有三个:
    ServletContextAttributeListener:在ServletContext域进行增、删、改属性时调用下面方法。
        public void attributeAdded(ServletContextAttributeEvent evt)
        public void attributeRemoved(ServletContextAttributeEvent evt)
        public void attributeReplaced(ServletContextAttributeEvent evt)
    HttpSessionAttributeListener:在HttpSession域进行增、删、改属性时调用下面方法
        public void attributeAdded(HttpSessionBindingEvent evt)
        public void attributeRemoved (HttpSessionBindingEvent evt)
        public void attributeReplaced (HttpSessionBindingEvent evt)
    ServletRequestAttributeListener:在ServletRequest域进行增、删、改属性时调用下面方法
        public void attributeAdded(ServletRequestAttributeEvent evt)
        public void attributeRemoved (ServletRequestAttributeEvent evt)
        public void attributeReplaced (ServletRequestAttributeEvent evt)
      操作属性监听器参数:事件对象功能进行介绍
        ServletContextAttributeEvent
            String getName():获取当前操作的属性名;
            Object getValue():获取当前操作的属性值;
            ServletContext getServletContext():获取ServletContext对象。
        HttpSessionBindingEvent
            String getName():获取当前操作的属性名;
            Object getValue():获取当前操作的属性值;
            HttpSession getSession():获取当前操作的session对象。
        ServletRequestAttributeEvent
            String getName():获取当前操作的属性名;
            Object getValue():获取当前操作的属性值;
            ServletRequest getServletRequest():获取当前操作的ServletRequest对象。
            ServletContext getServletContext():获取ServletContext对象;
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值