SEC7113: CSS was ignored due to mime type mismatch

2019-01-28 10:34发布

问题:

I am developing a Jsp-Servlet application. I deployed the application using Eclipse with Default Tomcat 7.

However after deploying the application, in Chrome/Firefox the UI gets rendered properly. Where as in IE10 or later is showing this warning in console and none of the UI elements are loaded.

SEC7113: CSS was ignored due to mime type mismatch

This is how the css files are referred

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <link rel="shortcut icon" href="images/rpt.ico" type="image/x-icon">
        <link href="css/custom.css" rel="stylesheet" type="text/css" />
    </head>
...............
</html>

How do I solve this issue?

Update If I run the site in Compatible mode, it's rendering fine. But how should I make it work even if it's not enabled.

I can see that Type is not coming as text/css. But Why?

回答1:

Ok,

I found that there's no way of doing from server side [tomcat] and tried with web.xml too. Then I found a workaround using a Filter Implementation

   @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        if(request.getHeader("accept")!=null && request.getHeader("accept").contains("css")){
            response.setHeader("Content-Type", "text/css");
        }
        chain.doFilter(req, response);
    }

I explicitly set text/css for css requests. Then it's working fine.