PrettyFaces 是一个非常简单的 URL 重写引擎。各种 SEO 都是可能的,而且真的很容易。不过我有一个小问题:(
使用漂亮的面孔,我有这个重写规则:
<url-mapping id="blogEntry">
<pattern value="/blog/#{shortUrl}" />
<view-id value="/blogEntry.jsf" />
</url-mapping>
因此 URL 栏看起来像:
http://host.com/blog/first-post
并且重写规则在内部将请求映射到:
http://host.com/blogEntry?shortUrl=first-post
我正在实现 OpenID,这意味着我需要为 OpenID 提供者提供一个返回 URL。但是,当我执行以下操作时:
originalUrl = Faces.getRequest().getRequestURL().toString()
我得到:
http://host.com/blogEntry.jsf
getQueryString() 返回一个空字符串
任何人都知道获取 purty URL 的方法:http://host.com/blog/first-post
或至少是查询字符串 shortUrl=first-post
最佳答案
您可以使用:PrettyContext.getCurrentInstance().getRequestUrl().toURL()
和 PrettyContext.getCurrentInstance().getRequestQueryString().toQueryString()
类似的论坛帖子: http://ocpsoft.org/support/topic/how-get-the-original-request-uri-from-jsf
关于java - JSF2 和 PrettyFaces...如何获取原始 URL 或查询字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11916243/