Filter过滤器导致CSS样式失效

Filter过滤器导致CSS样式失效

F12打开控制台看到如下警告:

Filter过滤器导致CSS样式失效

问题代码:

public class CharacterEncodingFilter extends HttpFilter {

    @Override
    public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        //解决post 请求乱码
       request.setCharacterEncoding("UTF-8");
       //解决响应乱码
        response.setContentType("text/html;charset=UTF-8");
        chain.doFilter(request,response);
    }
}

将代码更改为 

public class CharacterEncodingFilter extends HttpFilter {

    @Override
    public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        //解决post 请求乱码
       request.setCharacterEncoding("UTF-8");
       //解决响应乱码
        response.setCharacterEncoding("UTF-8");
        chain.doFilter(request,response);
    }
}

response.setContentType("text/html;charset=UTF-8");更改response.setCharacterEncoding("UTF-8");

刷新,提交代码,清除缓存,问题得到解决!

上一篇:python之request post数据的方法


下一篇:Cookie&Session笔记