<ui:composition template="/template.xhtml"> 无效路径:/template.xhtml

<ui:composition template="/template.xhtml"> Invalid path : /template.xhtml

资源库合同不适用于 Weblogic 12.1.1。请问是不是版本问题?尝试访问 c1/index.xhtml

时遇到以下错误

javax.faces.view.facelets.TagAttributeException: //seamnt/prd101/weblogic12_projects/testdomain/servers/testserver/stage/JavaWeb/JavaWeb/c1/index.xhtml @8,48 无效路径:/ template.xhtml

这是war结构:

WEB-INF/faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.1"
                          xmlns="http://java.sun.com/xml/ns/javaee"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd">
        <application>
                <resource-library-contracts>
                        <contract-mapping>
                                <url-pattern>/c1/*</url-pattern>
                                <contracts>c1</contracts>
                        </contract-mapping>
                        <contract-mapping>
                                <url-pattern>/c2/*</url-pattern>
                                <contracts>c2</contracts>
                        </contract-mapping>
                </resource-library-contracts>
        </application>
</faces-config>

contracts/c1/template.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
      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>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <h:outputStylesheet name="default.css"/>
        <title><ui:insert name="title">c1 Template</ui:insert></title>
    </h:head>

    <h:body styleClass="body">
        <h1><ui:insert name="h1">template.xhtml</ui:insert></h1>
        <h:graphicImage url="#{resource['duke.handsOnHips.gif']}"
                                alt="Duke with hands on hips"/>
        <ui:insert name="content"/>
    </h:body>
</html>

c1/index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:composition template="/template.xhtml">
        <ui:define name="title">c1 Index</ui:define>
        <ui:define name="h1">index.xhtml</ui:define>
        <ui:define name="content">
            <h:form>
                <div>Name: #{requestScopedBean.name}</div>
                <label>Name:
                    <h:inputText id="username"
                                 title="Name: "
                                 value="#{requestScopedBean.name}"
                                 required="true"
                                 requiredMessage="Error: A name is required."
                                 maxlength="25" />
                </label>
                <br/>
                <h:commandButton id="submit" value="Submit"
                                 action="index" />
                <h:commandButton id="reset" value="Reset" type="reset" />
            </h:form>
            <div class="messagecolor">
                <h:messages showSummary="true"
                            showDetail="false"
                            errorStyle="color: #d20005"
                            infoStyle="color: blue"/>
            </div>
        </ui:define>
    </ui:composition>
</html>

资源库契约在 JSF 2.2 中是 introduced

您只使用了 JSF 2.1。这不仅表明您在 faces-config.xml 中使用 version="2.1",而且 WebLogic 12.1.x 内置了 JSF 2.1。

从逻辑上讲,您有 2 个选择:

  1. 升级到 JSF 2.2(这意味着,升级到 WebLogic 12。2.x)。
  2. 放弃使用资源库合同的想法。无论如何,这是一个相当无用的功能。

最后但同样重要的是,确保您的版本与学习资源相匹配,并且您赶上了当前可用的版本。确保您以正确的方式学习 JSF。 Start here