How to get the real request URL in Struts with Tiles?

eltehaem picture eltehaem · Sep 25, 2008 · Viewed 20.3k times · Source

When you're using Tiles with Struts and do...

request.getRequestURL()

...you get the URL to e.g. /WEB-INF/jsp/layout/newLayout.jsp instead of the real URL that was entered/clicked by the user, something like /context/action.do.

In newer Struts versions, 1.3.x and after, you can use the solution mentioned on javaranch and get the real URL using the request attribute ORIGINAL_URI_KEY.

But how to do this in Struts 1.2.x?

Answer

digz6666 picture digz6666 · Jul 21, 2010

I use this, which also works on Spring:

<% out.println(request.getAttribute("javax.servlet.forward.request_uri")); %>

If you also need the query string (contributed by matchew):

<% out.println(request.getAttribute("javax.servlet.forward.query_string")); %>