tags:

views:

3764

answers:

5

When you use tiles in struts and do

request.getRequestURL()

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

In new struts versions, 1.3.x and after, you can use solution mentioned on javaranch and get real url using attribute ORIGINAL_URI_KEY attribute.

But how to do this in struts 1.2.x?

A: 

I don't know if Struts 1.2.x has a similar Globals constant, but you could create your own in at least two ways:

  • get the original request URL in the Action and set it on the request, and call that from the JSP
  • use a Servlet Filter to do the same thing
Mwanji Ezana
+3  A: 

This works in Struts 1.2

private String getOriginalUri(HttpServletRequest request) {
    String targetUrl = request.getServletPath();
    if (request.getQueryString() != null) {
        targetUrl += "?" + request.getQueryString();
    }
    return targetUrl;
}
Steve McLeod
A: 

I use this.

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

When you query request.getRequestURL() from your view/jsp/tiles layer, it's already another rewritten request.

As Mwanji Ezana mentions, the most suitable way is to save it to separate property on the action execution phase. You may want to automate this process with the help of interceptors in Struts2.

alexzender