Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get correct current URL in JSP in Spring webapp

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

like image 727
user405935 Avatar asked Mar 14 '12 23:03

user405935


2 Answers

The best way would be to use EL like this:

${requestScope['javax.servlet.forward.request_uri']} 
like image 118
Paulius Matulionis Avatar answered Oct 04 '22 14:10

Paulius Matulionis


Maybe you are looking for something like:

<%= new UrlPathHelper().getOriginatingRequestUri(request) %> 

This is not that elegant but solved my problem.

like image 26
izilotti Avatar answered Oct 04 '22 14:10

izilotti