tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig McClanahan <Craig.McClana...@eng.sun.com>
Subject Re: getting the absolute path of the requested resource in a servlet
Date Wed, 03 May 2000 00:08:27 GMT
"Dunkle, Ed" wrote:

> This seems to be an anomalie:
> getServletConfig().getServletContext().getRealPath(req.getRequestURI())
>
> returns something like:
> abspath/mycontext/mycontext/filename
>
> I would think the desired behavior would be:
> abspath/mycontext/filename
>
> Comments??
>

The argument to getRealPath() is supposed to be context-relative, but you are
passing it a server-relative URI (the getRequestURI() value includes the
context path prefix).

The way to get what you want is to construct a context-relative URI out of
the appropriate request path elements:

    String uri = request.getServletPath();
    if (request.getPathInfo() != null)
        uri += request.getPathInfo();
    String pathname = getServletContext().getRealPath(uri);

and you will get back the desired behavior you asked for.

>
> Thanks,
> Ed
>

Craig McClanahan



Mime
View raw message