Been try to learn JSF, and sometimes I see the URL is .jsf
and sometimes is .xhtml
. Can sometimes fill my knowledge, please? When I create a JSF using Facelet, the file extension is .xhtml
, so where does .jsf
URL extension come from?
views:
295answers:
1The .jsf
extension is where the FacesServlet
is by default mapped on in the web.xml
.
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
The .xhtml
extension is of the actual Facelets page as you've physically placed in the webcontent of your webapp, e.g. Webapp/WebContent/page.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
and load/process its JSF components.
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>.html</param-value>
</context-param>
This will change the FacesServlet
to locate page.html
instad of (default) page.xhtml
.