zoukankan      html  css  js  c++  java
  • Servlet3.0的注解自定义原生Listener监听器实战

    简介:监听器介绍和Servlet3.0的注解自定义原生Listener监听器实战

      自定义Listener(常用的监听器 servletContextListener、httpSessionListener、servletRequestListener)

      代码示例:

      RequestListener.java

     1 package net.xdclass.demo.listener;
     2 
     3 import javax.servlet.ServletContextEvent;
     4 import javax.servlet.ServletContextListener;
     5 import javax.servlet.annotation.WebListener;
     6 
     7 @WebListener
     8 public class CustomContextListener implements ServletContextListener{
     9 
    10     //主要作为资源加载
    11     @Override
    12     public void contextInitialized(ServletContextEvent sce) {
    13         System.out.println("======contextInitialized========");
    14         
    15     }
    16 
    17     @Override
    18     public void contextDestroyed(ServletContextEvent sce) {
    19         System.out.println("======contextDestroyed========");
    20         
    21     }
    22 
    23 }

      

      CustomContextListener.java:

     1 package net.xdclass.demo.listener;
     2 
     3 import javax.servlet.ServletRequestEvent;
     4 import javax.servlet.ServletRequestListener;
     5 import javax.servlet.annotation.WebListener;
     6 
     7 @WebListener
     8 public class RequestListener implements ServletRequestListener {
     9 
    10     //主要作为统计
    11     @Override
    12     public void requestDestroyed(ServletRequestEvent sre) {
    13         // TODO Auto-generated method stub
    14         System.out.println("======requestDestroyed========");
    15     }
    16 
    17     @Override
    18     public void requestInitialized(ServletRequestEvent sre) {
    19         System.out.println("======requestInitialized========");
    20         
    21     }
    22 
    23    
    24 }

  • 相关阅读:
    模拟100 题解
    模拟99 题解
    模拟98 题解
    模拟97 题解
    模拟96 题解
    模拟95 题解
    模拟94 题解
    模拟93 题解
    模拟92 题解
    Django-- 多数据库联用
  • 原文地址:https://www.cnblogs.com/116970u/p/10250909.html
Copyright © 2011-2022 走看看