tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Warren <>
Subject Re: virtual host getRealPath
Date Sun, 05 Nov 2006 02:36:49 GMT
Hi Chris,

Thanks for your response.  After poking around a little more, it seems that the call

provides the proper local file path for me.  Any reason not to use that?


Christopher Schultz <> wrote:  Peter,

> I'm trying to figure out why I get repeated directory names when calling
> "application.getRealPath(request.getRequestURI())" from an index.jsp
> file. Clearly there's something about virtual hosts and contexts that
> I'm missing.

I suppose you /could/ do this, but usually URIs and directory structures
usually don't map exactly to one another.

> A request for the url:
> C:\Documents and Settings\Peter\My Documents\dev\webapps\\gallery\gallery

Yeah. Since your URL contains the prefix "/gallery" already, it's being
added. When you call "getRealPath", you're getting something rooted in
"...\dev\webapps\\gallery", which is the root of your
webapp. Since "/gallery" in the URI, too, you're doubling it.

You need to clip out the context path.

This ought to do it for you:

String path = request.getRequestURI();
path = path.substring(request.getContextPath());
path = application.getRealPath(path);

Note that letting users' URIs drive files being loaded from the disk
might be considered a security risk. I don't know your deployment model
or anything like that; I just figured I'd mention it.

Hope that helps,

Cheap Talk? Check out Yahoo! Messenger's low  PC-to-Phone call rates.
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message