> > What should the behaviour be if I call forward() on
> > a RequestDispatcher that (I know) doesn't exist?
> >   (Ya, ya, I get the same behaviour as if I didn't know
> >    it doesn't exist :-)
> > 
> > For example:
> > 
> >    getServletContext().
> >       getRequestDispatcher("/I_know_this_page_doesnt_exist.html").
> >          forward(request, response);
> > 
> > I would expect a NullPointerException but that is not what I get.
> > Instead, I see the following output in my browser window (Mozilla 0.92):
> >    <html><body></body></html>
> > Or "The document contains no data" from Netscape 4.7.
> > And, if I use lwp-request I get a 404 error which is reasonable.
> > 
> > What "should" I get?
> > 
> > The javadoc for ServletContext says:
> >    "This method returns null if the ServletContext cannot
> >     return a RequestDispatcher for any reason."
> > But I'm not sure what that reason might be given that a bogus URL
> > doesn't seem to do it.  Also, the spec doesn't say anything about
> > bad URLs.
> > 
> 
> I *like* the interesting questions :-).
>
> The answer depends on a precise understanding of what the spec says.  It
> says that you get a RequestDispatcher for the servlet that will handle
> the request URI you specify.

Ok, in the Dispatching Requests chapter (8) in Sevlet Spec v2.3 PFD 2, it
says
  "If no servlet can be resolved based on the given path, a
   RequestDispatcher is provided that returns the content for that path."

and that content is a 404 error.

>  In Tomcat, there is an implicit mapping like
> this:
> 
>   <servlet-mapping>
>     <servlet-name> default </servlet-name>
>     <url-pattern> / <url-pattern>
>   </servlet-mapping>
> 
> which says, in effect, "the 'default' servlet handles *all* requests that
> are not mapped to anything else".  Thus, there will never be a URL for
> which you cannot return a RequestDispatcher.

So that is an implementation detail.  I.E.  that is how catalina implements
the spec.  Why does the spec allow for getRequestDispatcher to return null?
Now that I've asked that, I don't actually remember seeing in the spec that
is can return null.  Oh yeah, in the Duke Bookstore example from Sun, they
say in the source code that getRequestDispatcher() can return null.

> When you actually try to RequestDispatcher.forward() to this, you will get
> a 404 error, just as if you'd asked for it directly.
> 
> > Thanks,
> > Kevin.
> 
> Craig

Kevin.


____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie

Reply via email to