Exception information:
Resource interpreted as Stylesheet but transferred with MIME type text/html:
Possible causes
The filter or some place turns all resource requests to text/HTML
Inspection method
Using browser to view request header and response header
Mainly check the content type of request header and response header
The style sheet should be text/CSS, and the request sent to the server and the server’s response to the client should be text/CSS
The problem I personally encountered in the project is that when using the filter to code all requests, the CSS file is also processed
The filter code before modification is
System.out.println("**********AllFilter start work*********");
HttpServletRequest request=(HttpServletRequest)req;
HttpServletResponse response=(HttpServletResponse)res;
response.setCharacterEncoding("text/html; charset=UTF-8");
Treatment method
The request should be classified. When it is a kind of file such as CSS, it is requested in the original way and not processed. Other requests are processed again. The modified code is as follows:
System.out.println("**********AllFilter start work*********");
HttpServletRequest request=(HttpServletRequest)req;
HttpServletResponse response=(HttpServletResponse)res;
String url=request.getRequestURI();
System.out.println("url:" +url);
if(url.indexOf(".css")>0||url.indexOf(".js")>0||url.indexOf(".png")>0) {
chain.doFilter(request, response);
return;
}
response.setContentType("text/html;text/html; charset=UTF-8");