使用查询字符串获取重写的URL

编程入门 行业动态 更新时间:2024-10-21 02:46:14
本文介绍了使用查询字符串获取重写的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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/mypage?param=test

如果我这样做的话

#{view.viewId}

我知道

mypage.xhtml

mypage.xhtml

我想得到的是:

mypage?param = test

mypage?param=test

推荐答案

UIViewRoot#getViewId() 返回JSF视图ID.您需要使用 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

本文发布于:2023-11-17 12:09:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609954.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   字符串   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!