How will you access the REQUEST_URI from inside a Struts 2 Action? In perl/php/ruby it's easily available via ENV["REQUEST_URI"] and so on. In java it appears the PageContext.getErrorData().getRequestURI() is exactly what I am searching for, but sadly, the PageContext doesn't seem to be defined inside the action, either since the ErrorDocument redirection helps make the request not seem like a mistake, or since it is defined later.

A specific example

Given an apache fronted (mod_jk/ajp) struts 2 application on tomcat arrived at through the ErrorDocument 404 configuration in apache. Using the following particulars:

-- Original request url (which triggers the 404) --

http://server/totally/bogus/path

-- http.conf --

ErrorDocument 404 /struts2app/lookup.action

-- struts action --

public String bogusUrlLookup() {
    HttpServletRequest request = ServletActionContext.getRequest();

    // contains /lookup.action as does request.getRequestURI();
    String url = RequestUtils.getServletPath(request);

    // PageContext is null, so I cannot reach ErrorData from it.
    log.info("pageContext="+ServletActionContext.getPageContext());

    // Not in the ENV
    // Map env = System.getenv();

    // Not in the ATTRIBUTES
    // request.getAttributeNames()

    // Not in HEADER
    // request.getHeaderNames()

    return ERROR;
}

Again all I want may be the string "/totally/bogus/path", however in the above mentioned action the only real url string will be able to find is "/struts2app/research.action". I am associated with the ErrorDocument since the totally/bogus/path isn't likely to become inside the namespace of my application because apache serves other non-tomcat assets.

request.getAttribute("javax.servlet.forward.request_uri")

Use

JkEnvVar REDIRECT_URL ""

inside your httpd.conf file

after which use request.getAttribute("REDIRECT_URL") to obtain the variable inside your jsp/servlets