Refresh Add Advanced Option

I need to refresh a webpage, but in the update request I want to add an additional parameter, so I have 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 currentUrl with parameters (e.g. http: // localhost: 8080 / mywebapp? Param1 = var1 & param2 = var2 ) of the request from implicit jsp objects. I have something like $ {pageContext.request.requestURL}, but this returns the jsp url, not the request url.

thanks

+6
java jsp servlets jstl
source share
2 answers

If the JSP has been redirected, you can get the original request URL ${requestScope['javax.servlet.forward.request_uri']} and the query string of the original request at ${requestScope['javax.servlet.forward.query_string']} .

You can, by the way, find an overview of all these β€œhidden” forward attributes here and.

+4
source share

Based on BalusC 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 the address bar? If so, you can write a JavaScript function to get the parameters, and then change your href .

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; 

This will be much shorter if you use jQuery or PrototypeJS such as the JavaScript framework.

+2
source share

All Articles