我需要将哪些XHTML文件放在/ WEB-INF中,哪些不是?
问题描述:
这些问题后:我需要将哪些XHTML文件放在/ WEB-INF中,哪些不是?
- https://stackoverflow.com/questions/8589315/jsf2-dynamic-template
- Dynamic ui:include
- How can I retrieve an object on @WindowScoped?
- How can I check if an object stored with @WindowScoped is stored correctly?
- ICE Faces and error in creation of a bean in WindowScoped
,我写的所有解决一个 “愚蠢” 的问题的JSF2框架,我无法直接链接到存储在/WEB-INF
子文件夹中的页面。之后,我对Google和Stackoverflow做了一些研究,我会知道一件事情:我如何构建一个JSF2 Web项目?
特别是,我究竟在哪里放置了XHTML页面?
答
/WEB-INF
文件夹中的文件确实无法由最终用户公开访问。所以你不能有像http://localhost:8080/contextname/WEB-INF/some.xhtml
这样的东西。这将是一个潜在的安全漏洞,因为最终用户可以查看/WEB-INF/web.xml
等等。
但是,您可以使用/WEB-INF
文件夹,把主模板文件,包括文件和标记文件。例如,这是摆外面/WEB-INF
和下面的模板客户page.xhtml
是http://localhost:8080/contextname/page.xhtml
访问:
<ui:composition template="/WEB-INF/templates/template.xhtml"
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"
>
<ui:define name="content">
...
<ui:include src="/WEB-INF/includes/include.xhtml" />
...
</ui:define>
</ui:composition>
在/WEB-INF
中放置主模板和包含文件的优点是,最终用户将无法通过在浏览器地址栏中输入/猜测其URL来直接打开它们。正在访问的直接访问的普通页面和模板客户端不得放置在/WEB-INF
文件夹中。
顺便说一下,复合组件文件反过来也不应该公开访问,但他们是通过规定需要放置在默认公开访问的/resources
文件夹中。如果你确保你访问使用therefor provided components所有资源,以便它们被/resources
在URL从未访问(而是由/javax.faces.resource
),那么你可以将以下约束添加到web.xml
,以阻止对/resources
文件夹的所有公众访问:
<security-constraint>
<display-name>Restrict direct access to the /resources folder.</display-name>
<web-resource-collection>
<web-resource-name>The /resources folder.</web-resource-name>
<url-pattern>/resources/*</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
这是一个突出的问题,涉及到facelets的许多方面。 – Thufir 2015-02-15 09:38:05