You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Jonathan Pierce <Jo...@seagram.com> on 2000/04/28 18:02:08 UTC

Re[2]: ServletContext.getRealPath still broken?

Costin,

Thanks for the explanation of this. It wasn't clear to me from what I read in
the spec. Perhaps some examples need to be added to the spec.

As you said,

getServletContext ().getRealPath ("") does what I want, giving me the real path
of the context.

Jonathan

____________________Reply Separator____________________
Subject:    Re: ServletContext.getRealPath still broken?
Author: tomcat-dev@jakarta.apache.org
Date:       4/28/00 8:11 AM

Hi Jonathan,

I think getRealPath() return the right result from the point of view
of the spec. ( it may be wrong from other views :-)

It will return the real path _relative_ to the webapp ( or context ),
as opposed to the real path for an absolute URL.

If you want the real path of the context you'll have to call getRealPath("")
( in general - remove the contextPath from the URI ).

The reason seems to be mainly security - to keep different web applications
completely isolated, which is an useful feature. You can still find real paths
in different contexts by using getContext( path ).getRealPath(
pathMinuxCtxPath).
( getContext(path)  may allow/deny access to a different context based on
security settings )

If you prefer a different behavior or more informations - mail to the
servletapi-feedback !

Costin

Jonathan Pierce wrote:

> ServletContext.getRealPath seems to still return the wrong result in
Tomcat3.1.
> Is this a known bug?
>
> I added the following two lines to the SnoopServlet example in the Tomcat3.1
> distribution to illustrate this:
>
> out.println("request.getContextPath (): " + request.getContextPath ());
>     out.println("getServletContext().getRealPath (request.getContextPath ()):
"
> + getServletContext().getRealPath (request.getContextPath ()));
>
> The results were as below which looks wrong !!!.
>
> request.getContextPath ():
>     /examples
>
> getServletContext().getRealPath (request.getContextPath ()):
> D:\Tomcat3.1\dist\tomcat\webapps\examples\examples
>
> The server.xml entry is:
> <Context path="/examples" docBase="webapps/examples" debug="0"
reloadable="true"
> >
> </Context>
>
> My Tomcat_Home directory is:
> D:|Tomcat3.1\dist\tomcat
>
> Jonathan Pierce (Not to be confused with the other Jonathan posting to this
> list.)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org