Get rewritten URL with query string

半城伤御伤魂 提交于 2019-12-25 16:57:41

问题


I'm using tuckey URL rewriting with JSF.

I would like to get the relative URL including parameters that the user sees: e.g.

example.com/mypage?param=test

At the moment if I do

#{view.viewId}

I get

mypage.xhtml

what I want to get is:

mypage?param=test


回答1:


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}

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']}

Clumsy yes. Consider hiding away in <c:set> of a master template, or an utility tag/function.



来源:https://stackoverflow.com/questions/33212601/get-rewritten-url-with-query-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!