Resource interpreted as Stylesheet but transferred with MIME type text/html

响应头中ContentType参数要和请求头中Accept参数保持一致,比如application/javascript,text/css,text/html
如果不保持一致,有可能导致浏览器无法识别响应内容,
下图展示的就是正确的css样式文件的请求和响应头

Resource interpreted as Stylesheet but transferred with MIME type text/html

如果不一致的改动方式,在全局过滤器中增加响应头的设置:

String contextType = ((HttpServletRequest) request).getHeader("Accept");
httpResponse.setContentType(contextType == null ? "text/html;charset=utf-8" : contextType+";charset=utf-8");

因为我的项目是utf-8格式的,所以此处写的是utf-8,如果你的项目是其他格式,本处换成其他格式即可

另外经实测,Tomcat7和Tomcat8在本处的处理是不同的,Tomcat8必须写成如上格式,Tomcat7可以统一设置成text/html

 

参考链接:https://blog.****.net/sky_cui/article/details/86703706