Resource interpreted as Stylesheet but transferred with MIME type text/html 报错
方法一:
方法二:
@WebFilter("/")
public class EncodingFilter implements Filter{
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
String contentType = ((HttpServletRequest)request).getHeader("Accept");
response.setContentType(contentType == null ? "text/html;charset=utf-8" : contentType + ";charset=utf-8");
chain.doFilter(request, response);
}
}
方法三:
获取url类型,只要是css或者js等其他资源就修改contentType
方法四:
使用ServletResponse的子类HttpServletResponse来设置过滤。完美解决!