问题描述
大多数教程都提出了类似于以下 web.xml 的默认 JSF 配置:
Most tutorials propose a default JSF configuration similar to the following web.xml:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
使用此配置,如果相应的 URL 以文件扩展名 .jsf 结尾(例如 http://localhost/welcome.jsf).是否可以将 web.xml 配置为使用相同的 *.xhtml 文件将不以 .jsf 结尾的 URL 也作为 JSF 页面进行处理?
With this configuration the corresponding *.xhtml files in my webapp are only found by the Faces Servlet if the corresponding URLs ends with the file extension .jsf (e.g. http://localhost/welcome.jsf). Is it possible to configure web.xml so URLs that do not end with .jsf are also processed as JSF pages using the same *.xhtml files?
换句话说,我希望拥有不依赖于服务器端实现的 URL.
In other words I would like to have URLs that do not depend on the server side implementation.
推荐答案
您可以使用过滤器隐藏此扩展程序并使您的 URL SEO 友好.Filter 的一种这样的实现是 PrettyFaces.
You can use Filter to hide this extension and make your URL SEO friendly. One such implementation of Filter is PrettyFaces.
例如:如果你需要 http://host:port/yourapp/login
用你的 login.xhtml
来解析,那么在漂亮的过滤器中配置以下方式
For example:If you need http://host:port/yourapp/login
to resolve with your login.xhtml
then in pretty filter configure following way
<url-mapping id="login">
<pattern> /login </pattern>
<view-id> /legacy/user/login.jsf </view-id>
</url-mapping>
查看两分钟视频教程
这篇关于如何配置没有文件扩展名的 JSF url 映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!