WEB-INF 目录中的 JSF 文件,我如何访问它们? [英] JSF files inside WEB-INF directory, how do I access them?

查看:23
本文介绍了WEB-INF 目录中的 JSF 文件,我如何访问它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的 JSF 2.0 xhtml 文件放在 WEB-INFjsf 下.那我如何访问它们?我知道 WEB-INF 里面的任何东西都不会暴露在外面,所以我需要一个控制器来将我重定向到相应的 JSP,对吗?(这也是模型 2 模式 iirc).

I want to put my JSF 2.0 xhtml files under WEB-INFjsf. How do I access them then? I know that anything inside WEB-INF isn't exposed to the outside, so I need a controller to redirect me to the corresponding JSP, right? (This is also the model 2 pattern iirc).

我可以使用 web.xml/faces-config.xml 中的参数来实现吗?我认为 FacesServlet 是我的 web 应用程序的控制器,所以它应该用于此目的?

Can I achieve this with a parameter inside web.xml/faces-config.xml? I think the FacesServlet is the controller of my webapp so it should serve this purpose?

还有一个关于理解模型 2 模式的问题.是否每个动作都必须首先进入 servlet,然后由它处理下一个可能的步骤?所以一个简单的 <a href="anotherPage.html"/> 在这个模式中是被禁止的,因为它不会进入控制 servlet?

And another question for understanding the Model 2 Pattern. Does every action have to go first to a servlet which then handles the next possible step? So a simple <a href="anotherPage.html" /> is forbidden in this pattern since it doesn't go to the controlling servlet?

推荐答案

我想将我的 JSF 2.0 xhtml 文件放在 WEB-INFjsf 下.那么我如何访问它们?

你不能./WEB-INF 文件夹中的文件不可直接访问.

You cannot. Files in /WEB-INF folder are not directly accessible.

有两种方法可以解决 JSF 源文件可公开访问的问题.

There are two options to workaround the problem of JSF source files being public accessible.

  1. FacesServlet 映射到 *.xhtml 而不是 *.jsf.

  1. Map the FacesServlet on *.xhtml instead of *.jsf.

或者,通过 web.xml 中的 限制对 *.xhtml 的直接访问.

Or, restrict direct access on *.xhtml by a <security-constraint> in web.xml.

<security-constraint>
    <display-name>Restrict direct access to XHTML files</display-name>
    <web-resource-collection>
        <web-resource-name>XHTML files</web-resource-name>
        <url-pattern>*.xhtml</url-pattern>
    </web-resource-collection>
    <auth-constraint />
</security-constraint> 

另见:

  • 哪个XHTML 文件是否需要放在/WEB-INF 中,哪些不需要?
  • JSF Facelets:有时我看到 URL 是 .jsf,有时是 .xhtml.为什么?
  • 还有一个关于理解模型 2 模式的问题.是否每个动作都必须先进入 servlet,然后由它处理下一个可能的步骤?

    FacesServlet 已经做到了.是控制器.使用 JSF,您已经以一个简单的 javabean 作为模型和 JSP/Facelets 文件作为视图结束.作为控制器的 FacesServlet 已经从您手中接过了请求参数收集、验证、转换、模型更新和导航的所有繁琐工作.

    The FacesServlet already does that. It's the controller. With JSF you already end up with a simple javabean as model and JSP/Facelets file as view. The FacesServlet as being the controller has already taken all the nasty work of request parameter gathering, validation, conversion, model updating and navigation from your hands.

    那么简单的 <a href="anotherPage.html"/> 在这种模式中是被禁止的,因为它不会进入控制 servlet?

    So a simple <a href="anotherPage.html" /> is forbidden in this pattern since it doesn't go to the controlling servlet?

    不,完全没问题.控制器将在需要时启动.如果资源不需要控制器(即静态资源),那么你也不需要让它通过某个控制器.

    No, it's perfectly fine. The controller will kick in whenever needed. If the resource doesn't need a controller (i.e. static resource), then you also don't need to let it pass through some controller.

    以后,请在单独的 Stack Overflow 问题中提出多个问题.

    In the future, please ask multiple questions in separate Stack Overflow questions.

    这篇关于WEB-INF 目录中的 JSF 文件,我如何访问它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆