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

查看:34
本文介绍了将 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 映射到 扩展名.意思是,如果我的 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 是无扩展名的 URL,如果是,则执行 RequestDispatcher#forward() 调用附加了文件扩展名的 URL(你知道,转发不会不要像重定向那样修改当前的请求 URL).您还需要一个自定义的视图处理程序为 JSF 等生成所需的无扩展 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 的 FacesViews 这样您就不需要重新发明轮子了.在 FacesViews 展示页面的底部,您可以找到一些直接指向源代码的简单链接,它们可能会给您一些启发.

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天全站免登陆