0

为什么我在 JSF 中刷新具有模板的页面时会丢失所有 CSS 和 JS?

我的模板:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
        <link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
        <title>Facelets Template</title>
    </h:head>

    <h:body>


        <div id="top" class="top">
            <ui:insert name="top">
                <h:form>
                    <h:commandButton value="Home" action="#{auth.goHome()}"/>
                    <h:commandButton value="Logout" action="#{auth.logout}"/>
                </h:form>
            </ui:insert>
        </div>
        <div>
            <div id="left">
                <ui:insert name="left">Left</ui:insert>
            </div>
            <div id="content" class="left_content">
                <ui:insert name="content">Content</ui:insert>
            </div>
        </div>
    </h:body>

</html>

子页面:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:composition template="/contentTemplate.xhtml" >

        </ui:composition>
    </h:body>
</html>

在此处输入图像描述

**GET http://localhost:11032/Integration/Common/resources/css/default.css 404 (Not Found) welcome.xhtml:5
GET http://localhost:11032/Integration/Common/resources/css/cssLayout.css 404 (Not Found)**
4

1 回答 1

1

开始尝试更换

<link href="./resources/css/default.css" rel="stylesheet" type="text/css" /> 

(和其他CSS)与

<h:outputStylesheet name="css/default.css" target="head" /> (do same for the other css)

如果那不起作用,您可以尝试使用#{facesContext.externalContext.requestContextPath}

<link href="#{facesContext.externalContext.requestContextPath}/css/default.css" rel="styleSheet" type="text/css"/>     
于 2012-08-14T07:10:08.793 回答