刷新添加额外参数
我需要刷新网页,但在刷新请求中我想添加一个额外的参数,所以我有类似的内容:
<c:url value="currentUrl" var="newUrl">
<c:param name="newParam" value="newValue"/>
</c:url>
<a href="${newUrl}">Refresh</a>
如何获取带有参数的 currentUrl (例如 http://localhost:8080/mywebapp?param1=var1¶m2=var2)来自 jsp 隐式对象的请求。 我虽然有类似 ${pageContext.request.requestURL} 的内容,但这返回的是 jsp 的 url,而不是请求 url。
谢谢
I need to refresh the webpage, but in the refresh request I want to add an extra parameter, so I have though in something like:
<c:url value="currentUrl" var="newUrl">
<c:param name="newParam" value="newValue"/>
</c:url>
<a href="${newUrl}">Refresh</a>
How can I get the currentUrl with the params (for instance http://localhost:8080/mywebapp?param1=var1¶m2=var2) of the request from the implicit objects of the jsp.
I have though in something like ${pageContext.request.requestURL}, but this returns the url of the jsp, not the request url.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果JSP已经被转发,则可以通过
${requestScope['javax.servlet.forward.request_uri']}
获取原始请求URL,通过以下方式获取原始请求查询字符串:${requestScope['javax.servlet.forward.query_string']}
。顺便说一下,您可以在 此处找到所有这些“隐藏”转发属性的概述 和此处。
If the JSP has been forwarded, you can get the original request URL by
${requestScope['javax.servlet.forward.request_uri']}
and the original request query string by${requestScope['javax.servlet.forward.query_string']}
.You can by the way find an overview of all those "hidden" forward attributes here and here.
基于BalusC的回答
你可以尝试这两个,
JavaScript Approach
你指的是地址栏中的URL吗?如果是这种情况,您可以编写一个 JavaScript 函数来获取参数,然后修改相关的
href
。例如,
如果您使用 jQuery 或 PrototypeJS(如 JavaScript 框架),它会短得多。
Based on BalusC's answer
You can try these two,
JavaScript Approach
Do you mean the URL in address bar? If that’s the case you can write a JavaScript function to get the parameters and then modify your
href
in question.For example,
It would much shorter, if you are using jQuery or PrototypeJS like JavaScript framework.