Refresh adding an extra parameter
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 ${pageCont开发者_如何学运维ext.request.requestURL}, but this returns the url of the jsp, not the request url.
Thanks
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.
Based on BalusC's answer
You can try these two,
${requestScope['javax.servlet.forward.request_uri']}
${requestScope['javax.servlet.forward.query_string']}
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,
<a id="refresh" href="${newUrl}">Refresh</a>
...
var url = window.location.href;
url += url.split("?").length > 1 ? "&newParam=value" : "?newParam=value";
document.getElementById("refresh").href = url;
It would much shorter, if you are using jQuery or PrototypeJS like JavaScript framework.
精彩评论