2020.4.16 Resource interpreted as stylesheet but transferred with MIME type text/html

本地调试JavaWeb项目时,在一次清空缓存之后突然出现了如下报错:
Resource interpreted as stylesheet but transferred with MIME type text/html
具体情况是我的项目的css文件全部加载失败
根据报错分析可知,是css文件被全部当成了html文件解析了,这明显是不正确的

解决方法:
查找了过滤器Filter的代码,原来是response对象的ContextType全部设置为了text/html类型,响应的css文件也被过滤了。
注释掉这行代码即可

HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) rep;
//获取请求方法
String method = request.getMethod();
//解决post请求中文数据乱码问题
if(method.equalsIgnoreCase("post")){
   	request.setCharacterEncoding("utf-8");
}
response.setContentType("text/html;charset=utf-8");
filterChain.doFilter(request,response);
原创文章 187 获赞 29 访问量 6万+

猜你喜欢

转载自blog.csdn.net/weixin_43826242/article/details/105558433