How is the URL set when an application is deployed on WAS server? Other than the context path I am setting, I am getting a /faces/
in the URL. I have no clue from where this is coming from.
问题:
回答1:
The /faces/
is recognizable as JSF 1.0/1.1-style URL pattern where FacesServlet
is often by default mapped on based on IDE-generated project configuratoin which weren't edited afterwards by the developer. You can see this in web.xml
as something like this:
<servlet-mapping>
<servlet-name>Faces Servlet<servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
Perhaps there's also a <welcome-file>
on e.g. faces/index.xhtml
or so.
In order to get rid of it, just replace it by *.xhtml
.
<servlet-mapping>
<servlet-name>Faces Servlet<servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
This way you can open the JSF page by http://example.com/context/page.xhtml
instead of http://example.com/context/faces/page.xhtml
in order to trigger the FacesServlet
(it's namely the one responsible for all the JSF works).
Or, when you're actually using legacy JSF 1.x and/or when you're actually using legacy JSP instead of its successor Facelets (XHTML), then you could use *.jsf
instead.
<servlet-mapping>
<servlet-name>Faces Servlet<servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
This way you can open the JSF page by http://example.com/context/page.jsf
instead of http://example.com/context/faces/page.jsp
.
See also:
- JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?