I\'m trying to get a correct current URL in JSP in Spring webapp. I\'m trying to use the following fragment in the JSP file:
${pageContext.request.requestURL}
I used the following in a similar situation. ${currentUrl} can then be Used where needed. Needs core tag library
<c:url value = "" var = "currentUrl" ></c:url>
You can make Interceptor and set request attribute e.g.
request.setAttribute("__SELF",request.getRequestURI);
and in jsp
<form action="${__SELF}" ></form>
I just found the right answer for your question. The key is using Spring Tags.
<spring:url value="" />
If you put the value attribute empty, Spring will display the mapping URL set in your @RequestMapping.
*<% String myURI = request.getAttribute("javax.servlet.forward.request_uri").toString(); %>
<% String[] split = myURI.split("/"); %>
<% System.out.println("My url is-->"+ myURI
+ " My url splitter length --->"+split.length
+"last value"+split[4]);%>
<%-- <jsp:param name="split[4]" value="split[4]" /> --%>
<c:set var="orgIdForController" value="<%= split[4] %>" />
<a type="button" class="btn btn-default btn-xs"
href="${pageContext.request.contextPath}/supplier/add/${orgIdForController}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Add
</a>
- List item*
Anyone who wants to know about other than the reuqest URI, for example a query string, you can check all the names of the variables in the code of RequestDispatcher(of Servlet API 3.1+) interface.
You can get the query string like this:
${requestScope['javax.servlet.forward.query_string']}
In a jsp
file:
request.getAttribute("javax.servlet.forward.request_uri")