tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amy Roh <amy...@apache.org>
Subject Re: ServletContext.getResource() never null?
Date Mon, 13 Aug 2001 22:30:23 GMT


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




Mime
View raw message