Tiles and ${pageContext.request.requestURL}

gotch4 picture gotch4 · Nov 26, 2012 · Viewed 7.6k times · Source

Usually, to get the request URL in a JSP, I would use

${pageContext.request.requestURL}

but on the project I am working with (because we use tiles I guess) if I run the above I get something like

WEB-INF/pathTo/pageName.jsp

even if the request URL is another and that is just the path of the JSP included using tiles.

How do I get the request URL using JSP EL in this situation?

Answer

majorbanzai picture majorbanzai · Jan 10, 2013

Tiles has already rewritten/forwarded the request, so by the time your jsp gets the request, it wasn't the original request.

Two things you can do..

  1. in your controller grab the original url and place it as an attribute request.setAttribute("origRequestURL", request.getRequestURL()) and then use ${origRequestURL}

  2. see if this attribute maintained the original before the forward: <% request.getAttribute("javax.servlet.forward.request_uri"); %> or ${requestScope['javax.servlet.forward.request_uri']}