如何在没有文件扩展名的情况下配置JSF url映射? [英] How do I configure JSF url mappings without file extensions?
问题描述
大多数教程都提出了类似于以下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>
使用此配置,我的webapp中相应的* .xhtml文件只能由Faces Servlet找到,如果相应的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的此类实现之一是 Pretty Filter 。
You can use Filter to hide this extension and make your URL SEO friendly,One of such implementation of Filter is Pretty Filter.
例如:
如果您需要 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映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!