This method returns null if the servlet container cannot return a RequestDispatcher.
Returns: a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the servlet container cannot return a RequestDispatcher
Tyler Wright wrote:I hate it when authors give (un-intentionally, I hope) wrong information.
Having checked this example against AppServer 9.1 (Glassfish 2), I also obtain a 404 response with a warning in the server logs. It therefore seems the behaviour of this particular container has changed between AppServer 8 used in the 2006 edition of SCWCD Study Companion and Glassfish as recommended in the new 2nd Edition. Just to be more confusing still, if you use ServletContext.getNamedDispatcher("blahblah") where "blahblah" is a non-existent servlet mapping, it will return null rather than present a 404 error. So if you want to avoid potential cross-container issues with NullPointerExceptions being thrown, I would always check for the RequestDispatcher being null.
Tyler Wright wrote:Charles, what you are saying is that one the 'correct' (answers) possible outcomes for this question is container dependent.
If no servlet can be resolved based on the given path, a RequestDispatcher is provided that returns the content for that path.
The error page mechanism does not intervene when errors occur when invoked using the RequestDispatcher or filter.doFilter method. In this way, a filter or servlet using the RequestDispatcher has the opportunity to handle errors generated.
a small re-write of the question to avoid the ambiguity.
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton