以编程方式禁用在Intranet中运行的站点的IE-8兼容模式并呈现.xhtml页面

时间:2014-03-11 03:04:57

标签: java internet-explorer jsf-2 internet-explorer-8 ie8-compatibility-mode

我有一个JSF应用程序,在intranet中运行.xhtml页面。我尝试删除默认元标记并添加元标记

 <meta http-equiv="X-UA-Compatible" content="IE=8" />

但是没有用。这个解决方案只适用于普通的html页面,或者是否有任何其他方法可以用来编程禁用兼容模式。

1 个答案:

答案 0 :(得分:2)

如果您想阻止所有JSF页面的兼容性模式,更好使用过滤器:

<强>爪哇

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>