zoukankan      html  css  js  c++  java
  • 【JavaEE企业应用实战学习记录】requestListener

     1 package sanglp.servlet;
     2 
     3 import javax.servlet.*;
     4 import javax.servlet.annotation.WebListener;
     5 import javax.servlet.http.HttpServletRequest;
     6 
     7 /**
     8  * Created by Administrator on 2016/10/5.
     9  */
    10 @WebListener
    11 public class RequestListener implements ServletRequestListener,ServletRequestAttributeListener {
    12 
    13     //用户请求到底,被初始化时触发该方法
    14     @Override
    15     public void requestInitialized(ServletRequestEvent servletRequestEvent) {
    16         HttpServletRequest request=(HttpServletRequest)servletRequestEvent.getServletRequest();
    17         System.out.println("发向"+request.getRequestURI()+"请求被初始化");
    18     }
    19     //用户请求到底,被销毁时触发该方法
    20     @Override
    21     public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
    22         HttpServletRequest request=(HttpServletRequest)servletRequestEvent.getServletRequest();
    23         System.out.println("发向"+request.getRequestURI()+"请求被销毁");
    24 
    25     }
    26 
    27     @Override
    28     public void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {
    29         ServletContext application=servletRequestAttributeEvent.getServletContext();
    30         //获取添加的属性名和属性值
    31         String name=servletRequestAttributeEvent.getName();
    32         Object value=servletRequestAttributeEvent.getValue();
    33         System.out.println(application+"范围内添加了"+name+"值为"+value+"的属性");
    34 
    35     }
    36 
    37     @Override
    38     public void attributeRemoved(ServletRequestAttributeEvent servletRequestAttributeEvent) {
    39         ServletContext application=servletRequestAttributeEvent.getServletContext();
    40         //获取添加的属性名和属性值
    41         String name=servletRequestAttributeEvent.getName();
    42         Object value=servletRequestAttributeEvent.getValue();
    43         System.out.println(application+"范围内删除了"+name+"值为"+value+"的属性");
    44     }
    45 
    46     @Override
    47     public void attributeReplaced(ServletRequestAttributeEvent servletRequestAttributeEvent) {
    48         ServletContext application=servletRequestAttributeEvent.getServletContext();
    49         //获取添加的属性名和属性值
    50         String name=servletRequestAttributeEvent.getName();
    51         Object value=servletRequestAttributeEvent.getValue();
    52         System.out.println(application+"范围内替换了"+name+"值为"+value+"的属性");
    53     }
    54 }
  • 相关阅读:
    「SDOI2018」物理实验
    「SDOI 2018」战略游戏
    「CodeChef Dec13 REALSET」 Petya and Sequence 循环卷积
    关于微信卡券投放code接口报错原因
    composer update maatwebsite/excel 之后 在linux机子上出现500解决方案
    开启mysql 服务【window】
    thinkphp在linux上部署环境(500情况)
    如何推广微信小程序到企业微信
    linux 阿里云远程连接mysql
    php7以上 不支持mcrypt_module_open方法问题【微信开放平台】
  • 原文地址:https://www.cnblogs.com/dream-to-pku/p/5933234.html
Copyright © 2011-2022 走看看