intranet jsf application opening in compatibility

2019-08-07 14:04发布

问题:

i have made a intranet website in jsf, primefaces. becuase of IE 9 defaults it opens in compatability view. i know i am supposed to use the tag

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

but it doesnt work instead it shows

HTML1115: X-UA-Compatible META tag ('IE=edge') ignored because document mode is already finalized.

i have used the tag as such

<!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>

this is what it shows in the developers tools

<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>

i am guessing this is happening beacuse as mentioned in alot of other posts the meta tag has to be at the top of the head but i dont know how i could achive this.

how do i make my meta tag to be the first tag in my application

this is completely what the console in IE is showing

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. 

回答1:

In jsf PrimeFaces you have to use the following to reorder the tags

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

It moved the meta to the top of the generated header using that code and it worked

from the following link



回答2:

You can use a servlet filter to solve it

Add this to your 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 code:

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 {
    }

}