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

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

问题描述

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

I want to put my JSF 2.0 xhtml files under WEB-INF\jsf. 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是我的webapp的控制器所以它应该用于此目的吗?

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-INF \ jsf下。我如何访问它们?

你不能。无法直接访问 / 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 c $ c> *。xhtml 而不是 *。jsf

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

或者,在 *。xhtml 对< security-constraint> 的直接访问> web.xml 。

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> 




参见:




  • 我需要在/ WEB-INF中放入哪些XHTML文件?哪些不是?

  • JSF Facelets:有时我看到URL是.jsf和有时.xhtml。为什么?

  • See also:

    • Which XHTML files do I need to put in /WEB-INF and which not?
    • JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?

    • 另一个理解模型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.

      • What components are MVC in JSF MVC framework?
      • JSF Controller, Service and DAO

      所以一个简单的< 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天全站免登陆