tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: getRealPath returns the base path??
Date Sat, 03 Jun 2000 16:55:08 GMT
Travis Reeder wrote:

> When using the code
> String filepath = getServletContext().getRealPath("/");
> in a file like
> d:\web\app\subdir\file.jsp
>
> filepath == "d:\web\app\"
>
> Now shouldn't that return "d:\web\app\subdir\" ???
>
> It's not really a problem once you know what it returns, but you would think
> that it would return the subdir folder.
>

You need to review the Javadocs for the getRealPath() method.  It returns the
pathname of whatever virtual path you specify, resolved against the document
root for your web application.  It doesn't make any difference at all what
servlet or JSP file you call it in.

If your web app's document root is "d:\web\app", then getRealPath("/") will
return "d:\web\app".  If you want the pathname to your subdirectory, call this
instead:

    String filepath = getServletContext().getRealPath("/subdir");

which will return "d:\web\app\subdir" in this case.

>
> Travis Reeder
> Director, Internet Technologies
> Xabre.com
>

Craig McClanahan





Mime
View raw message