DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5432>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5432

request.getRequestDispatcher("nothing")

[EMAIL PROTECTED] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX



------- Additional Comments From [EMAIL PROTECTED]  2001-12-14 18:47 -------
To be precise, this is what the Javadocs say:

    "This method returns null if the ServletContext
    cannot return a RequestDispatcher."

which is not quite the same as "when it does not know the resource".

The way a RequestDispatcher is located is this:  all the servlet mappings in the
current web application are compared to the path you specify.  If no servlet can
be found to handle this path, you'll get a null back -- if you had submitted
such a request from your browser, you'd get a 403 BAD REQUEST error).

Now, Tomcat supports serving static resources from your application (a feature
not required in the Servlet Spec, by the way).  The way this is accomplished is
through the "default servlet mapping" feature of the Servlet Specification.  You
will find the following entry in $CATALINA_HOME/conf/web.xml:

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

What the special mapping pattern "/" means is "whenever you are processing a URL
that does not match any other servlet, give it to the 'default' servlet", which
is the servlet that actually serves the static resource.  In other words, there
will *always* be a servlet to map to a servlet -- therefore you will not get a
null back from the getRequestDispatcher() call.

Note that the container has no way to know whether the path is meaningful to the
default servlet or not (remember, you can replace the default servlet with your
own if you want).  Therefore, it's just going to hand the request on to that
servlet.

If you want to programmatically check whether a resource exists, you can say:

    URL url = getServletContext().getResource("/foo.txt");
    if (url == null)
        ... the resource does not exist ...

One final note -- Tomcat has worked this way the entire time I've been working
with it (in other words, since version 3.0).

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to