gotch4
gotch4

Reputation: 13269

Tiles and ${pageContext.request.requestURL}

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?

Upvotes: 7

Views: 8712

Answers (1)

majorbanzai
majorbanzai

Reputation: 571

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']}

Upvotes: 4

Related Questions