Servlet 3.1 api中@WebListener实现servlet监听

在Servlet 3.1中,使用@WebListener注解来标识一个Servlet监听器,相关的监听接口有:

1.ServletContextListener

public interface ServletContextListener extends EventListener {
//监听容器初始化事件    
public void contextInitialized(ServletContextEvent sce);

//监听容器销毁事件    
public void contextDestroyed(ServletContextEvent sce);
}

2.ServletContextAttributeListener

public interface ServletContextAttributeListener extends EventListener {
// 属性被添加
public void attributeAdded(ServletContextAttributeEvent event);

// 属性被移除
public void attributeRemoved(ServletContextAttributeEvent event);

// 属性被更新
public void attributeReplaced(ServletContextAttributeEvent event);
}

3.ServletRequestListener

public interface ServletRequestListener extends EventListener {
// 请求销毁
public void requestDestroyed(ServletRequestEvent sre);

// 请求初始化
public void requestInitialized(ServletRequestEvent sre);
}

4.ServletRequestAttributeListener

public interface ServletRequestAttributeListener extends EventListener {
// 属性添加
public void attributeAdded(ServletRequestAttributeEvent srae);


// 属生删除
public void attributeRemoved(ServletRequestAttributeEvent srae);

// 属性替换
public void attributeReplaced(ServletRequestAttributeEvent srae);
}

5.HttpSessionListener

public interface HttpSessionListener extends EventListener {
// 会话创建
public void sessionCreated(HttpSessionEvent se);

// 会话销毁
public void sessionDestroyed(HttpSessionEvent se);
}

6.HttpSessionAttributeListener

public interface HttpSessionAttributeListener extends EventListener {
// 属性添加
public void attributeAdded(HttpSessionBindingEvent event);

// 属性移除
public void attributeRemoved(HttpSessionBindingEvent event);

// 属性替换
public void attributeReplaced(HttpSessionBindingEvent event);
}

7.HttpSessionActivationListener 

public interface HttpSessionActivationListener extends EventListener { 
// 钝化
public void sessionWillPassivate(HttpSessionEvent se); 

// 活化
public void sessionDidActivate(HttpSessionEvent se);
}
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享