zoukankan      html  css  js  c++  java
  • 十、添加过滤器

    方法1、添加自己的过滤器

    1.1建包com.myz.web.filters,在包下新建Myfliter类

    package com.myz.web.filters;
    
    import java.io.IOException;
    
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServlet;
    
    public class MyFilter extends HttpServlet implements Filter {
    
        public void doFilter(ServletRequest arg0, ServletResponse arg1,
                FilterChain arg2) throws IOException, ServletException {
            // TODO Auto-generated method stub
            arg0.setCharacterEncoding("utf-8");
            arg2.doFilter(arg0, arg1);
        }
    
        public void init(FilterConfig arg0) throws ServletException {
            // TODO Auto-generated method stub
    
        }
    
    }

    1.2.web.xml中配置filter信息

    <filter>
            <filter-name>myFilter</filter-name>
            <filter-class>com.myz.web.filters.MyFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>myFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

    方法2.使用spring提供的过滤器,仅需在web.xml中配置

    <filter>
        <filter-name>encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  • 相关阅读:
    性能测试知多少吞吐量
    性能测试知多少性能测试工具原理与架构
    性能测试知多少了解前端性能
    性能测试知多少响应时间
    性能测试知多少性能测试流程
    LoadRunner脚本编写之三(事务函数)
    测试人员的家在哪儿
    oracle的启动过程
    Oracle表空间(tablespaces)
    LoadRunner脚本编写之二
  • 原文地址:https://www.cnblogs.com/myz666/p/8436527.html
Copyright © 2011-2022 走看看