• Filter


    过滤器

         1. 过滤中的所有代码,在过滤特定请求的时候都会执行     
         2. 必须要让过滤器继续执行 
    
    public class FilterEncoding  implements Filter {
    
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
            System.out.println("已经初始化了");
        }
    
        @Override
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
            servletRequest.setCharacterEncoding("utf-8");
            servletResponse.setCharacterEncoding("utf-8");
            servletResponse.setContentType("text/html;charset=utf-8");
            System.out.println("过滤前");
            filterChain.doFilter(servletRequest,servletResponse);
            System.out.println("过滤后");
        }
    
        @Override
        public void destroy() {
            System.out.println("销毁");
        }
    }
    
    

    映射过滤器:

     <servlet>
            <servlet-name>showFilter</servlet-name>
            <servlet-class>com.xia.Filter.Servlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>showFilter</servlet-name>
            <url-pattern>/show</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>showFilter</servlet-name>
            <url-pattern>/Filter/show</url-pattern>
        </servlet-mapping>
       
        <filter>
            <filter-name>f</filter-name>
            <filter-class>com.xia.Filter.FilterEncoding</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>f</filter-name>
            <url-pattern>/Filter/show</url-pattern>
        </filter-mapping>
    
  • 相关阅读:
    什么是垃圾回收
    Oracle GoldenGate学习之Goldengate介绍
    JVM虚拟机选项:Xms Xmx PermSize MaxPermSize区别
    查看linux系统版本命令
    Case when 的用法,简单Case函数
    case when then else end
    ORACLE视图添加备注
    修改 tomcat 内存
    Linux 内存机制详解宝典
    oracle正则表达式regexp_like的用法详解
  • 原文地址:https://www.cnblogs.com/xiaxiaopi/p/14396302.html
Copyright © 2020-2023  润新知