将JSF .xhtml文件映射到无扩展名 [英] Mapping JSF .xhtml files to no extension

查看:158
本文介绍了将JSF .xhtml文件映射到无扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSF中,我可以将Faces Servlet映射到各种URL模式.例如.到*.xhtml.

In JSF I can map the Faces Servlet to various URL patterns. E.g. to *.xhtml.

但是我想要的是将Faces Servlet映射到 no 扩展.意思是,如果我的Web根目录中有页面customers.xhtml,我想使用http://example.com/customers进行请求.

What I want however is map the Faces Servlet to no extension. Meaning, if I have a page customers.xhtml in my web root, I would like to request this using http://example.com/customers.

我看了一个问题如何配置没有文件扩展名的JSF url映射?,这种方法在某种程度上可行,但是它要求我分别映射我拥有的每个文件(如果我输入错了,请更正).

I looked at the question How do I configure JSF url mappings without file extensions? and this works to some degree, but it requires me to map each and every file I have individually (correct me if I'm wrong).

如何将我所有的.xhtml文件映射到Faces Servlet中而不必分别进行映射?

How can I map all my .xhtml files in one go to the Faces Servlet without having to map them individually?

推荐答案

使用标准方法是不可能的.您基本上需要对/*上映射的 servlet过滤器进行自制,并检查当前请求URL是否为无扩展名,如果是,则执行视图处理程序以为JSF <h:form><h:link>等生成所需的无扩展URL.

That's not possible using the standard means. You basically need to homebrew a servlet filter which is mapped on /* and checks if the current request URL is an extensionless one and if so, then perform a RequestDispatcher#forward() call on the URL with the file extension appended (you know, a forward does not modify the current request URL as a redirect would do). You also need a custom view handler to produce the desired extensionless URLs for JSF <h:form>, <h:link>, etc.

或者,您可以使用 PrettyFaces 或OmniFaces的

Alternatively, you can use PrettyFaces or OmniFaces' FacesViews so that you don't need to reinvent the wheel. At the bottom of the FacesViews showcase page you can find some easy links directly to the source code which may give you some inspiration.

这篇关于将JSF .xhtml文件映射到无扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆