Api for ServletContext # getRequestDispatcher () says:
This method returns null if the ServletContext cannot return RequestDispatcher.
and
Returns: a RequestDispatcher object that acts as a wrapper for the resource at the specified path or null if the ServletContext cannot return RequestDispatcher
Why is ServletContext unable to return RequestDispatcher? At first I realized that if an invalid path were accepted, but it does not return null, this will lead to 404 in the browser.
I check the null value before calling the forward () method, and in the logs I see that after a while RequestDispatcher is null, but I donโt know why, and I canโt find out how to duplicate it.
thanks
Update
Like Fazal, I tried creating the RequestDispatcher at http://www.google.com/ to find out what would happen. This threw an IllegalArgumentException
java.lang.IllegalArgumentException: Path http://www.google.com/ does not start with a "/"
An exception was found in my try / catch block, so I had no way to check if RequestDispatcher was null or call the forward () method.
So, should there be another way for the ServletContext # getRequestDispatcher () method to return null without throwing an exception?
source share