Templates 未找到JSF嵌套模板文件异常
我在使用另一个嵌套模板的模板时遇到问题 我明白了Templates 未找到JSF嵌套模板文件异常,templates,jsf-2,path,facelets,Templates,Jsf 2,Path,Facelets,我在使用另一个嵌套模板的模板时遇到问题 我明白了 java.io.FileNotFoundException at org.apache.naming.resources.DirContextURLConnection.getInputStream(DirContextURLConnection.java:403) 我有一个基本模板: (./resources/css/template.xhtml) <html xmlns="http://www.w3.org/1999/xht
java.io.FileNotFoundException
at org.apache.naming.resources.DirContextURLConnection.getInputStream(DirContextURLConnection.java:403)
我有一个基本模板:
(./resources/css/template.xhtml)
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet library="css" name="stylesheet.css"/>
<title><ui:insert name="title"> Facelets template </ui:insert></title>
</h:head>
<h:body>
<div id="top" class="top_content">
<ui:insert name="top">Top</ui:insert>
</div>
<div>
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
</h:body>
(./resources/css/templateLogin.xhtml)
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="./resources/css/template.xhtml">
<ui:define name="title">
Some title
</ui:define>
<ui:define name="top">
<div id="top">
...code here
</div>
</ui:define>
</ui:composition>
(./resources/css/template.xhtml)
Facelets模板
顶部
内容
以及“继承”模板的templateLogin:
(./resources/css/template.xhtml)
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet library="css" name="stylesheet.css"/>
<title><ui:insert name="title"> Facelets template </ui:insert></title>
</h:head>
<h:body>
<div id="top" class="top_content">
<ui:insert name="top">Top</ui:insert>
</div>
<div>
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
</h:body>
(./resources/css/templateLogin.xhtml)
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="./resources/css/template.xhtml">
<ui:define name="title">
Some title
</ui:define>
<ui:define name="top">
<div id="top">
...code here
</div>
</ui:define>
</ui:composition>
(./resources/css/templateLogin.xhtml)
一些头衔
…这里是代码
我有一个欢迎文件,它是使用templateLogin的web应用程序的欢迎文件:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="./resources/css/templateLogin.xhtml">
<ui:define name="title">
Welcome title
</ui:define>
欢迎标题
正如我所说,我得到的文件没有找到异常。当我为欢迎文件定义为template template.xhtml时,没有错误。这是因为它在指定的路径中没有看到templateLogin.xhtml,但它确实在那里
有什么想法吗?谢谢。如果我看一下你的代码,就会发现一些奇怪的东西。您的主模板位于中 参考资料/css这很好。但是您的另一个模板也位于/resources/css中 你在信中说:
template="./resources/css/template.xhtml"
因此,您建议它位于/resources/resources/css中,是的,文件不在那里
因此,在您的计划中包括以下内容:
template="template.xhtml"
我不知道你的templateLogin.xhtml在哪里,但这里也要注意你的include去掉模板路径中的前导周期。前导周期使其相对于模板客户端的当前文件夹。如果模板路径以
/
开头,则它对于web内容根目录来说是绝对路径
因此,因此:
template="/resources/css/template.xhtml"
及
与具体问题无关,这些路径有两个问题:
/WEB-INF
文件夹中。例如
template="/WEB-INF/templates/layout.xhtml"
及
另见:
#{request.contextPath}/resources/css/default.css
将模板放入WEB-INF并修复路径正如您所说的,它修复了问题。谢谢你清晰而翔实的回答,我从你身上学到了很多!