How to get correct current URL in JSP in Spring webapp

user405935 picture user405935 · Mar 15, 2012 · Viewed 58.6k times · Source

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}

The issue is that the returned URL contains prefix and suffix defined by UrlBasedViewResolver. For example the correct URL is:

http://localhost:8080/page

But the returned one is:

http://localhost:8080/WEB-INF/jsp/page.jsp

Answer

Paulius Matulionis picture Paulius Matulionis · Sep 26, 2013

The best way would be to use EL like this:

${requestScope['javax.servlet.forward.request_uri']}