【问题标题】:JSF2 and PrettyFaces... how does one get the original URL or the query string?JSF2 和 PrettyFaces...如何获取原始 URL 或查询字符串?
【发布时间】:2012-08-08 14:47:27
【问题描述】:

PrettyFaces 是一个非常简单的 URL 重写引擎。各种 SEO 都是可能的,而且 真的很容易。不过我有一个小问题:(

使用漂亮的面孔,我有这个重写规则:

<url-mapping id="blogEntry">
    <pattern value="/blog/#{shortUrl}" />
    <view-id value="/blogEntry.jsf" />
</url-mapping>

所以网址栏看起来像:

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() 返回一个空字符串

任何人都知道获取纯 URL 的方法:http://host.com/blog/first-post 或至少查询字符串 shortUrl=first-post

【问题讨论】:

  • 你试过 FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("shortUrl");??
  • @RAvi 是的,它返回一个空地图。

标签: java jakarta-ee jsf-2 url-rewriting prettyfaces


【解决方案1】:

您可以使用:PrettyContext.getCurrentInstance().getRequestUrl().toURL()PrettyContext.getCurrentInstance().getRequestQueryString().toQueryString()

类似的论坛帖子: http://ocpsoft.org/support/topic/how-get-the-original-request-uri-from-jsf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    相关资源
    最近更新 更多