ServletContextAttributeListener的用法和实例

2021-08-03 18:01:47 浏览数 (1)

2)ServletContextAttributeListener:

ServletContextAttributeListener能监测到有人正在往ServletContext里添加属性。你可以采取相应的措施。

例 2.2.2.1

web.xml当中再加入一段话:

<listener>

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

</listener>

package com;

import javax.servlet.ServletContextAttributeEvent;

import javax.servlet.ServletContextAttributeListener;

public class MyServletContextAttributeListener implements ServletContextAttributeListener {

public void attributeAdded(ServletContextAttributeEvent arg0) {

System.out.println("增加了" arg0.getName() " "

arg0.getValue() );

}

public void attributeRemoved(ServletContextAttributeEvent arg0) {

System.out.println("去除了" arg0.getName() " "

arg0.getValue() );

}

public void attributeReplaced(ServletContextAttributeEvent arg0) {

System.out.println("取代了" arg0.getName() " "

arg0.getValue() "现在的新值是" arg0.getServletContext().getAttribute(arg0.getName()) );

}

}

更多请看:https://blog.csdn.net/qq_44638460/article/details/104101837

jsp

0 人点赞