4

我正在使用带有 primefaces 的 jsf2.0。我的应用程序在包括 IE8 在内的所有浏览器上都运行良好......但是当我在 IE9 中运行我的应用程序时,我的内部样式表甚至没有被浏览器(IE9)采用......样式被破坏了。

我的CSS在头上:

<h:head>
<meta http-equiv="X-UA-Compatible" content="IE=9" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Chennai Volunteers</title>
<link href="cv_website_styles.css" rel="stylesheet"  type="text/css" />
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script charset="utf-8" src="http://widgets.twimg.com/j/2/widget.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</h:head>

我在控制台中收到以下错误,

java.lang.IllegalArgumentException: ContentTypeList does not contain a supported content type: text/css
at org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.selectContentType(HtmlRendererUtils.java:1905)
at org.apache.myfaces.renderkit.html.HtmlRenderKitImpl.createResponseWriter(HtmlRenderKitImpl.java:223)
at org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase.renderView(JspViewDeclarationLanguageBase.java:154)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

提前致谢。

4

1 回答 1

14

我检查了您的网站 chennaivolunteers.org,我注意到它FacesServlet被映射到 URL 模式/faces/*而不是*.xhtml. 由于您仅使用相对<link><script>资源引用,因此它们也将(不必要地)通过FacesServlet

IE9 发送一个 CSS 文件Accept-Headertext/css而其他浏览器发送一个Accept-Header. 本身不应该响应请求text/css;*/*FacesServlettext/css

基本上有两种方法可以解决这个问题:

  • 摆脱/faces/*映射并将其替换为*.xhtml.

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    
  • <link>在和<script>(和)引用中使用域相对 URL,<img>以便它们永远不会通过/faces路径。

    <ui:param name="root" value="#{request.contextPath}/" />
    <link href="#{root}cv_website_styles.css" rel="stylesheet"  type="text/css" />
    <link rel="stylesheet" type="text/css" href="#{root}css/style.css"/>
    <script type="text/javascript" src="#{root}js/jquery.min.js"></script>
    <script type="text/javascript" src="#{root}js/script.js"></script>
    

    或者使用<base>标签,或者使用<h:outputStylesheet>and<h:outputScript>name代替。

顺便说一句,您的网站在几个资源上都有相当多的 404。也解决这个问题。检查浏览器内置 Web 开发工具集的“Net”、“Network”部分(在 IE9/Chrome/Firebug 中按 F12)。

于 2012-06-22T14:43:49.307 回答