【问题标题】:Which XHTML files do I need to put in /WEB-INF and which not?我需要将哪些 XHTML 文件放入 /WEB-INF 而哪些不需要?
【发布时间】:2012-02-20 08:30:44
【问题描述】:

在这些问题之后:

我写的所有内容都是为了解决 JSF2 框架的“愚蠢”问题,即我无法直接链接到存储在 /WEB-INF 子文件夹中的页面。之后我对 Google 和 Stackoverflow 做了一些研究,我知道了一件事:我如何构建一个 JSF2 Web 项目?

具体来说,XHT​​ML 页面到底应该放在哪里?

【问题讨论】:

  • 这是一个涉及到 facelets 很多方面的悬而未决的问题。

标签: jsf jsf-2 facelets web-inf


【解决方案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 访问:

<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 访问所有资源,这样它们就不会被URL 中的/resources 访问(而是通过/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> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    相关资源
    最近更新 更多