To programmatically disable IE-8 compatibility mode for the site running in intranet and rendering .xhtml pages

寵の児 提交于 2019-12-06 06:25:26

If you want to prevent the compatibility mode for all your JSF pages you better use a filter for this:

Java

public class NoCompatibilityMode implements Filter {

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
            ServletException {
        if (((HttpServletRequest) req).getRequestURI().endsWith(".js.jsf")
                || ((HttpServletRequest) req).getRequestURI().endsWith(".css.jsf")) {
            chain.doFilter(req, res);
        } else {
            HttpServletResponse response = (HttpServletResponse) res;
            response.setHeader("X-UA-Compatible", "IE=edge"); // No more Compatibility Mode
            chain.doFilter(req, res);
        }

    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {
    }

}

web.xml

<filter>
    <filter-name>NoCompatibilityMode</filter-name>
    <filter-class>my.package.name.NoCompatibilityMode</filter-class>
</filter>
<filter-mapping>
    <filter-name>NoCompatibilityMode</filter-name>
    <url-pattern>*.jsf</url-pattern>
</filter-mapping>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!