使用查询字符串重写 URL

Get rewritten URL with query string

我正在使用 tuckey URL 用 JSF 重写。

我想得到相对 URL 包括用户看到的参数: 例如

example.com/mypage?param=test

目前如果我这样做

#{view.viewId}

我明白了

mypage.xhtml

我想得到的是:

mypage?param=test

UIViewRoot#getViewId() returns the JSF view ID. You need to use HttpServletRequest#getRequestURI() to obtain the current request URI and HttpServletRequest#getQueryString()获取当前请求查询字符串。

#{request.requestURI}#{empty request.queryString ? '' : '?'}#{request.queryString}

或者,如果是转发的请求,将其作为分别以 RequestDispatcher.FORWARD_REQUEST_URI and RequestDispatcher.FORWARD_QUERY_STRING 键控的请求属性获取:

#{requestScope['javax.servlet.forward.request_uri']}#{empty requestScope['javax.servlet.forward.query_string'] ? '' : '?'}#{requestScope['javax.servlet.forward.query_string']}

笨拙是的。考虑隐藏在主模板 <c:set> 或实用程序 tag/function.