web.xml中配置编码过滤器两种方式

在web.xml配置filter时一定要放在所有过滤器之前

    
    
        encodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
        
            forceEncoding
            true
        
    

    
        encodingFilter
        /*
    

----------------------------------------------------------------------------------------------------------------------------------

public class EncodingFilter implements Filter {

    private String encoding = "utf-8";

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        if(filterConfig.getInitParameter("encoding")!=null){
            encoding=filterConfig.getInitParameter("encoding");
        }
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request=(HttpServletRequest)servletRequest;
        HttpServletResponse response=(HttpServletResponse)servletResponse;
        request.setCharacterEncoding(encoding);
        response.setCharacterEncoding(encoding);
        filterChain.doFilter(request,response);
    }


    @Override
    public void destroy() {

    }
}
  
    encodingFilter
    com.imooc.oa.global.EncodingFilter
    
      encoding
      utf-8
    
  
  
    encodingFilter
    /
  

(记录于慕课网SSM oa项目)

  
  
    CharacterEncodingFilter
    org.springframework.web.filter.CharacterEncodingFilter
    
      encoding
      UTF-8
    
    
      forceRequestEncoding
      true
    
    
      forceResponseEncoding
      true
    
  
  
    CharacterEncodingFilter
    /*
  

(记录于尚硅谷ssm-crud项目)

你可能感兴趣的:(web.xml)