有时我看到 JSF URL 是 *.jsf,有时是 *.xhtml,有时是/faces/*.为什么? [英] Sometimes I see JSF URL is *.jsf, sometimes *.xhtml and sometimes /faces/*. Why?
问题描述
一直在尝试学习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
扩展名是 实际 Facelets 文件,因为您已经实际放置在您的网络应用程序的网络内容中,例如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
中的以下
进行配置:
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.xhtml
的 page.xml
instad.
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>
这样您就不需要配置一些安全限制来隐藏原始源文件,以便在最终用户更改例如 .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.
- 我们可以在 web.xml 中使用正则表达式吗网址格式?
- 通过 <welcome-file> 设置默认主页在 JSF 项目中
- JSF 返回带有普通/原始 XHTML/XML/EL 源而不是呈现的 HTML 输出的空白/未解析页面
- 使用 .jsp 或 .xhtml 或 .jsf 扩展名创建 JSF 页面有什么区别
- 哪些 XHTML 文件需要放在/WEB-INF 中,哪些不需要?
- 自定义 FacesServlet
摆脱 .xhtml 扩展名
这篇关于有时我看到 JSF URL 是 *.jsf,有时是 *.xhtml,有时是/faces/*.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!