内联网jsf应用程序在IE9中以兼容模式打开

时间:2014-11-26 08:15:35

标签: java internet-explorer jsf primefaces

我在jsf,primefaces制作了一个内联网网站。因为IE 9默认它在兼容性视图中打开。 我知道我应该使用标签

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

但它不起作用而是显示

  

HTML1115:X-UA兼容的META标记(&#39; IE = edge&#39;)被忽略,因为   文件模式已经完成。

我已经使用了这样的标签

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>Wan</title>



</h:head>

这是它在开发人员工具中显示的内容

<head>
<TITLE>Wan</TITLE><LINK rel=stylesheet type=text/css href="/Wan/javax.faces.resource/theme.css.jsf?ln=primefaces-redmond"><LINK rel=stylesheet type=text/css href="/Wan/javax.faces.resource/primefaces.css.jsf?ln=primefaces&amp;v=5.1">
<SCRIPT type=text/javascript src="/Wan/javax.faces.resource/jquery/jquery.js.jsf?ln=primefaces&amp;v=5.1"></SCRIPT>

<SCRIPT type=text/javascript src="/Wan/javax.faces.resource/primefaces.js.jsf?ln=primefaces&amp;v=5.1"></SCRIPT>

<SCRIPT type=text/javascript src="/Wan/javax.faces.resource/jquery/jquery-plugins.js.jsf?ln=primefaces&amp;v=5.1"></SCRIPT>
<LINK rel=stylesheet type=text/css href="/Wan/javax.faces.resource/charts/charts.css.jsf?ln=primefaces&amp;v=5.1">
<SCRIPT type=text/javascript src="/Wan/javax.faces.resource/charts/charts.js.jsf?ln=primefaces&amp;v=5.1"></SCRIPT>

<STYLE id=ex_canvas_>canvas {
    TEXT-ALIGN: left; WIDTH: 300px; DISPLAY: inline-block; HEIGHT: 150px; OVERFLOW: hidden
}
</STYLE>
<LINK rel=stylesheet type=text/css href="/Wan/javax.faces.resource/wanstyle.css.jsf?ln=css">
<META content=IE=edge http-equiv=X-UA-Compatible>

我猜这种情况正在发生,因为很多其他帖子中提到元标记必须位于头顶但我不知道我怎么能实现这一点。

如何让我的元标记成为我的应用中的第一个标记

这完全是IE中控制台显示的内容

HTML1202: http://10.164.210.37:8080/Wan/welcome.jsf is running in Compatibility View because 'Display intranet sites in Compatibility View' is checked. 
welcome.jsf
HTML1115: X-UA-Compatible META tag ('IE=edge') ignored because document mode is already finalized. 
welcome.jsf
S15: :visited and :link styles can only differ by color. Some styles were not applied to :visited. 

2 个答案:

答案 0 :(得分:3)

在jsf PrimeFaces中,您必须使用以下内容重新排序标记

<f:facet name="first">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  </f:facet>

它使用该代码将元数据移动到生成的标题的顶部,并且它可以正常工作

来自以下link

答案 1 :(得分:2)

您可以使用servlet过滤器来解决它

将此添加到 web.xml

<filter>
    <filter-name>EdgeFilter</filter-name>
    <filter-class>com.my.package.filter.EdgeFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>EdgeFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
</filter-mapping>

Java代码:

public class EdgeFilter 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 {
    }

}