tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Preston L. Bannister" <pres...@home.com>
Subject RE: ServletRequest.getRealPath() deprecated? (Was: Is request.getRealPath() broken?)
Date Fri, 17 Mar 2000 17:25:07 GMT
> "Preston L. Bannister" wrote:
> > The Servlet 2.1 and 2.2 APIs (not the specs) tag ServletRequest.getRealPath() as
deprecated.

From: Craig R. McClanahan
> And they also document the suggested replacement -- ServletContext.getRealPath().

In existing implementations getRealPath() in ServletRequest and ServletContext are *not* equivalent,
nor should they be.  There is
context associated with the request (as in the setup described in my original message) and
not the servlet that is necessary to
perform the getRealPath() mapping.

Now we could change the meaning of the ServletContext to somehow include the context of the
request, but this breaks backwards
compatibility without adding any value that I can see.


> > In fact if I am writing a servlet that aims to run under an existing servlet engine,
as well as under Tomcat, then there is no
> > equivalent to request.getRealPath() in the case described (below).  The context
required to map a relative path to a real path
is
> > the context of the request, not the context of the servlet.
> >
> > This is in fact what is implemented by the other servlet engines with which I have
tested.
> >
> > What I propose is the following:
> >
> > 1.  Remove the deprecated tag from the ServletRequest.getRealPath().

> This would require a change to the servlet spec itself, not just to Tomcat ... it's not
something that can be accomplished in this
> forum.  It's also not the direction that things are moving (see below).

Understood (the part about the forum) though a pointer would be appreciated.  I don't spend
*all* my time with servlets/Jakarta :).

Maybe I'm missing something, but I suspect the "direction" may need a little adjustment :).


> > 3.  Fix the bug in Tomcat that causes ServletRequest.getRealPath() to return the
incorrect result (below).

> The bug needs to be looked at anyway.

Agreed :)  This morning...


> > Opinions??

> The preferred approach in 2.1/2.2 based servlet engines is to use getResource() or getResourceAsStream()
instead of
> getRealPath() to
> access local resources.  Now you are using context-relative URIs and you don't care whether
or not your resources are
> actually in an
> operating system file that you can read -- the servlet container resolves all this stuff
for you.

OK, I must be missing this completely.  I don't see how getResource() or getResourceAsStream()
gets me the same information.  Even
if it did, this would break backwards compatibility rather badly.

The resource that I am trying to locate is relative to the URI, not relative to the class.


Mime
View raw message