有时我看到JSF URL是* .jsf,有时是* .xhtml,有时是/faces/*.为什么? [英] Sometimes I see JSF URL is *.jsf, sometimes *.xhtml and sometimes /faces/*. Why?

查看:104
本文介绍了有时我看到JSF URL是* .jsf,有时是* .xhtml,有时是/faces/*.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经尝试学习JSF,有时我看到URL是*.jsf,有时是*.xhtml/faces/*.有人可以填补我的知识吗?当我使用Facelet创建JSF时,文件扩展名是.xhtml,那么.jsf URL扩展名从何而来?

Been try to learn JSF, and sometimes I see the URL is *.jsf and sometimes is *.xhtml or /faces/*. Can someone fill my knowledge, please? When I create a JSF using Facelet, the file extension is .xhtml, so where does .jsf URL extension come from?

推荐答案

.jsf扩展名是FacesServlet在JSF 1.2期间(通常映射在web.xml中)的位置.

The .jsf extension is where the FacesServlet is during the JSF 1.2 period often mapped on in the web.xml.

<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

.xhtml扩展名是 actual Facelets文件的扩展名,因为您实际上已将其放置在Web应用程序的Web内容中. Webapp/WebContent/page.xhtml.

The .xhtml extension is of the actual Facelets file as you've physically placed in the webcontent of your webapp, e.g. Webapp/WebContent/page.xhtml.

如果您使用.jsf扩展名调用此页面,例如http://localhost:8080/webapp/page.jsf,然后将调用FacesServlet,找到page.xhtml文件并解析/渲染其JSF组件.如果未调用FacesServlet,则最终用户将最终获得原始XHTML源代码(可以通过右键单击查看源代码看到).

If you invoke this page with the .jsf extension, e.g. http://localhost:8080/webapp/page.jsf then the FacesServlet will be invoked, locate the page.xhtml file and parse/render its JSF components. If the FacesServlet isn't invoked, then the enduser would end up getting the raw XHTML source code (which can be seen by rightclick, View Source).

有时使用*.faces扩展名或/faces/*文件夹映射.但这是从JSF 1.0/1.1时代开始的.您可以自由选择和使用想要让FacesServlet监听的任何映射,即使它是无话可说的*.xyz.实际页面本身应始终具有.xhtml扩展名,但这可以由web.xml中的以下<context-param>配置:

Sometimes a *.faces extension or /faces/* foldermapping is been used. But this was from back in the JSF 1.0/1.1 ages. You're free to choose and use whatever mapping you'd like to let FacesServlet listen on, even if it's a nothing-saying *.xyz. The actual page itself should always have the .xhtml extension, but this is configureable by the following <context-param> in web.xml:

<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xml</param-value>
</context-param>

这将更改FacesServlet以查找(默认)page.xhtmlpage.xml位置.

This will change the FacesServlet to locate page.xml instad of (default) page.xhtml.

最近,在JSF/Facelets 2.0中,使用了*.xhtml映射.在JSF/Facelets 1.x中,无法使用与物理文件相同的映射扩展名.这将导致无限循环.但是从JSF/Facelets 2.0开始,这是可能的,这使您可以通过http://localhost:8080/webapp/page.xhtml调用页面.

More recently, with JSF/Facelets 2.0 a *.xhtml mapping is been used. In JSF/Facelets 1.x it was not possible to use the same mapping extension as the physical file. It would result in an infinite loop. But since JSF/Facelets 2.0 it is possible and this allows you to call the page by http://localhost:8080/webapp/page.xhtml.

<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

这样,当最终用户将URL中的.jsf更改为浏览器地址栏中的.xhtml时,无需配置一些安全限制即可隐藏原始源文件.仍然需要工具(IDE和插件)和学习资源来赶上从*.jsf*.xhtml的提倡.根据JSF 2.3,默认情况下,FacesServlet也会在*.xhtml上自动注册(在/faces/**.faces*.jsf之后).这被反向移植到Mojarra 2.2.11.

This way you don't need to configure some security restrictions to hide the raw source files away for cases whenever the enduser changes for example .jsf in URL to .xhtml in browser address bar. Only tooling (IDEs and plugins) and learning resources still need to catch up the advocated move from *.jsf to *.xhtml. As per JSF 2.3, the FacesServlet will by default be autoregistered on *.xhtml too (next to /faces/*, *.faces and *.jsf). This is backported to Mojarra 2.2.11.

  • Can we use regular expressions in web.xml URL patterns?
  • Set default home page via <welcome-file> in JSF project
  • JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
  • What is the difference between creating JSF pages with .jsp or .xhtml or .jsf extension
  • Which XHTML files do I need to put in /WEB-INF and which not?
  • Customize FacesServlet <url-pattern> to get rid of .xhtml extension

这篇关于有时我看到JSF URL是* .jsf,有时是* .xhtml,有时是/faces/*.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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