springMVC中接收post方式提交表单时出现中文乱码

解决方法:

1.手动开发一个Myfilter实现filter接口,代码如下

public class MyFilter implements Filter {
    //读取局部初始化参数
    private String encoding;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        encoding = filterConfig.getInitParameter("encoding");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding(encoding);
        response.setCharacterEncoding(encoding);
        chain.doFilter(request,response); //放行
    }

    @Override
    public void destroy() {

    }
}

2.配置web.xml



charset
com.rjxy.controller.MyFilter


encoding
UTF-8



charset
/*
 
   
 
  

转载于:https://www.cnblogs.com/lkldeblog/p/10526166.html

你可能感兴趣的:(springMVC中接收post方式提交表单时出现中文乱码)