哪些 XHTML 文件需要放入 /WEB-INF 中,哪些不需要?
在这些问题之后:
- https://stackoverflow.com/questions/8589315/jsf2-dynamic-template
- < a href="https://stackoverflow.com/questions/8786793/dynamic-uiinclude">动态 ui:include
- 如何检索 @WindowScoped 上的对象?
- 如何检查是否使用 @WindowScoped 存储的对象是否正确存储?
- ICE Faces 和在 WindowScoped 中创建 bean 时出现的错误
,我编写这些都是为了解决 JSF2 框架的“愚蠢”问题,事实上我无法直接链接到存储在/WEB-INF
子文件夹。之后我在 Google 和 Stackoverflow 上做了一些研究,我知道了一件事:如何构建一个 JSF2 Web 项目?
特别是,我到底应该把 XHTML 页面放在哪里?
After these questions:
- 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
that I wrote all to resolve a "stupid" issue for the JSF2 framework, the fact that I can't link directly to a page stored in a /WEB-INF
subfolder. After that I did some research on Google and Stackoverflow I would know a thing: How do I structure a JSF2 web project?
In particular, where exactly do I put the XHTML pages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
/WEB-INF
文件夹中的文件确实不能被最终用户公开访问。所以你不能有像http://localhost:8080/contextname/WEB-INF/some.xhtml
这样的东西。这将是一个潜在的安全漏洞,因为最终用户将能够查看/WEB-INF/web.xml
等内容。但是,您可以使用
/WEB-INF
文件夹来放置主模板文件、包含文件和标记文件。例如,放置以下模板客户端page.xhtml
在/WEB-INF
外部,可通过http://localhost:8080/contextname/page.xhtml
访问:将主模板和包含文件放在
中的优点/WEB-INF
是最终用户无法通过在浏览器地址栏中输入/猜测其 URL 来直接打开它们。直接访问的普通页面和模板客户端不得放置在/WEB-INF
文件夹中。顺便说一句,复合组件文件也不应该公开访问,但是根据规范,它们需要放置在默认情况下可公开访问的
/resources
文件夹中。如果您确保使用因此提供的组件访问所有资源 以便它们永远不会被 URL 中的/resources
访问(而是通过/javax.faces.resource
),然后您可以添加对web.xml
进行以下约束,以阻止对/resources
文件夹的所有公共访问:Files in
/WEB-INF
folder are indeed not publicly accessible by enduser. So you cannot have something likehttp://localhost:8080/contextname/WEB-INF/some.xhtml
. That would be a potential security hole as the enduser would be able to view among others/WEB-INF/web.xml
and so on.You can however use the
/WEB-INF
folder to put master template files, include files and tag files in. For example, the following template clientpage.xhtml
which is placed outside/WEB-INF
and is accessible byhttp://localhost:8080/contextname/page.xhtml
:The advantage of placing master templates and include files in
/WEB-INF
is that the enduser won't be able to open them directly by entering/guessing its URL in the browser addres bar. The normal pages and template clients which are intented to be accessed directly must not be placed in/WEB-INF
folder.By the way, the composite component files are in turn also not supposed to be publicly accessible, however they are by specification required to be placed in
/resources
folder which is by default publicly accesible. If you make sure that you access all resources using the therefor provided components so that they are never accessed by/resources
in URL (but instead by/javax.faces.resource
), then you can add the following constraint toweb.xml
to block all public access to the/resources
folder: