Filter过滤器导致CSS样式失效

Filter过滤器导致CSS样式失效_第1张图片

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

问题代码:

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");

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

你可能感兴趣的:(css3,前端,filter)