使用查询字符串获取重写的URL [英] Get rewritten URL with query string
问题描述
我正在使用JSF中的曲棍球URL重写.
I'm using tuckey URL rewriting with JSF.
我想获得包括用户看到的参数在内的相对URL: 例如
I would like to get the relative URL including parameters that the user sees: e.g.
example.com/mypage?param=test
如果我这样做的话
#{view.viewId}
我知道
mypage.xhtml
mypage.xhtml
我想得到的是:
mypage?param = test
mypage?param=test
推荐答案
HttpServletRequest#getRequestURI()
获取当前请求URI和 HttpServletRequest#getQueryString()
获取当前请求查询字符串.
The UIViewRoot#getViewId()
returns the JSF view ID. You need to use HttpServletRequest#getRequestURI()
to obtain the current request URI and HttpServletRequest#getQueryString()
to obtain the current request query string.
#{request.requestURI}#{empty request.queryString ? '' : '?'}#{request.queryString}
或者,如果是转发的请求,则将其作为以 RequestDispatcher.FORWARD_REQUEST_URI
和 RequestDispatcher.FORWARD_QUERY_STRING
:
Or, if it's a forwarded request, get it as a request attribute keyed with RequestDispatcher.FORWARD_REQUEST_URI
and RequestDispatcher.FORWARD_QUERY_STRING
respectively:
#{requestScope['javax.servlet.forward.request_uri']}#{empty requestScope['javax.servlet.forward.query_string'] ? '' : '?'}#{requestScope['javax.servlet.forward.query_string']}
笨拙的是.考虑隐藏在主模板或工具标签/功能的<c:set>
中.
Clumsy yes. Consider hiding away in <c:set>
of a master template, or an utility tag/function.
这篇关于使用查询字符串获取重写的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!