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: http://www.nomad.org/gallery/
> C:\Documents and Settings\Peter\My 
> Documents\dev\webapps\www.nomad.org\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\www.nomad.org\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();
if(path.startsWith(request.getContextPath()))
    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,
-chris

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to