You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by chris monster <cm...@algorithmics.com> on 2001/08/13 23:51:15 UTC

ServletContext.getResource() never null?

in the api-docs for ServletContext.getResource( String path ), it is
further specified that:


"This method returns null if no resource is mapped to the pathname."

and

"The path must begin with a "/"..."


are these stipulations in the servlet api-docs valid?


in testing several containers including Tomcat 3.1.1, i was unable to
get a null ( where a test for null would have been, um, desirable ), nor
did it appear that the presence or absence of a leading "/" made any
difference.


by way of contrast, consider the tantalizingly similar:


java.lang.ClassLoader.getResource( String path )

which specifically does *not* expect a leading slash, and very
definitely returns null when the resource does not exist.
 


reference:

http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletContext.html

http://java.sun.com/j2se/1.3/docs/api/java/lang/ClassLoader.html

Re: ServletContext.getResource() never null?

Posted by Amy Roh <am...@apache.org>.

chris monster wrote:

> in the api-docs for ServletContext.getResource( String path ), it is
> further specified that:
>
> "This method returns null if no resource is mapped to the pathname."
>
> and
>
> "The path must begin with a "/"..."
>
> are these stipulations in the servlet api-docs valid?

Yes.

>
>
> in testing several containers including Tomcat 3.1.1, i was unable to
> get a null ( where a test for null would have been, um, desirable ), nor
> did it appear that the presence or absence of a leading "/" made any
> difference.
>

What did you get instead of null when there's no resource at that path?

I've used ServletContext.getResource( String path ) using Tomcat4 and it followed the
spec -- returns null if no resource is mapped and path must begin with a "/" relative
to the current context root.  However, I can't say much about tomcat3.1.1 since I
haven't tested against it.

Amy

>
> by way of contrast, consider the tantalizingly similar:
>
> java.lang.ClassLoader.getResource( String path )
>
> which specifically does *not* expect a leading slash, and very
> definitely returns null when the resource does not exist.
>
>
> reference:
>
> http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletContext.html
>
> http://java.sun.com/j2se/1.3/docs/api/java/lang/ClassLoader.html




Re: ServletContext.getResource() never null?

Posted by Amy Roh <am...@apache.org>.


chris monster wrote:

> > >
> > > in testing several containers including Tomcat 3.1.1, i was unable to
> > > get a null ( where a test for null would have been, um, desirable ), nor
> > > did it appear that the presence or absence of a leading "/" made any
> > > difference.
> > >
> >
> > Sounds like a bug in 3.1.1.  But it's unlikely anyone is going to bend
> > over backwards to fix it -- Tomcat 3.2 was released nine months ago
> > (current version is 3.2.3), and Tomcat 4.0 will be released as soon as the
> > servlet 2.3 and JSP 1.2 specs go final (real soon now).
> >
>
> Amy is correct - Tomcat 4.0b7 appears to return the expected results.
> Tomcat 3.2.3, however, appears to exhibit the same behaviour as 3.1.1,
> so...

I guess the bug wasn't fixed in 3.2.3 either.  You can file a bug report to keep
track of this bug.  At least 4.0 works :-).

Amy


Re: ServletContext.getResource() never null?

Posted by chris monster <cm...@algorithmics.com>.
> >
> > in testing several containers including Tomcat 3.1.1, i was unable to
> > get a null ( where a test for null would have been, um, desirable ), nor
> > did it appear that the presence or absence of a leading "/" made any
> > difference.
> >
> 
> Sounds like a bug in 3.1.1.  But it's unlikely anyone is going to bend
> over backwards to fix it -- Tomcat 3.2 was released nine months ago
> (current version is 3.2.3), and Tomcat 4.0 will be released as soon as the
> servlet 2.3 and JSP 1.2 specs go final (real soon now).
> 

Amy is correct - Tomcat 4.0b7 appears to return the expected results. 
Tomcat 3.2.3, however, appears to exhibit the same behaviour as 3.1.1,
so...

Re: ServletContext.getResource() never null?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 13 Aug 2001, chris monster wrote:

> in the api-docs for ServletContext.getResource( String path ), it is
> further specified that:
> 
> 
> "This method returns null if no resource is mapped to the pathname."
> 
> and
> 
> "The path must begin with a "/"..."
> 
> 
> are these stipulations in the servlet api-docs valid?
> 

Starting with Servlet 2.3, the API Javadocs are even included inside the
spec.  You can assume that they are authoritative.

> 
> in testing several containers including Tomcat 3.1.1, i was unable to
> get a null ( where a test for null would have been, um, desirable ), nor
> did it appear that the presence or absence of a leading "/" made any
> difference.
> 

Sounds like a bug in 3.1.1.  But it's unlikely anyone is going to bend
over backwards to fix it -- Tomcat 3.2 was released nine months ago
(current version is 3.2.3), and Tomcat 4.0 will be released as soon as the
servlet 2.3 and JSP 1.2 specs go final (real soon now).

By the way, at 3.2's initial release there were at least 150 bug fixes to
problems in 3.1, so this is not the only problem you will run into.

> 
> by way of contrast, consider the tantalizingly similar:
> 
> 
> java.lang.ClassLoader.getResource( String path )
> 
> which specifically does *not* expect a leading slash, and very
> definitely returns null when the resource does not exist.
>  

It also looks a totally different place -- inside /WEB-INF/classes or
inside JAR files under /WEB-INF/lib.

> 
> 
> reference:
> 
> http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletContext.html
> 
> http://java.sun.com/j2se/1.3/docs/api/java/lang/ClassLoader.html
> 

Craig McClanahan