I'm using a RequestDispatcher to forward to a JSP page. In my code, I need to be able to handle errors if the page that it tries to forward to a page that doesn't exist in order to avoid seeing:
javax.servlet.ServletException: The page '/myapp/mydir/vehicleChange1.jsp' does not exist.
in the browser window (the path to the page is determined at runtime based on some input parameters). Anyway, for some reason I am having trouble with this. I've tried 2 ways:
1. I've tried catching the ServletException in the servlet. Doesn't work. I can't find any documentation about this, but I'm guessing that by the time the exception is thrown, my servlet has lost control.
2. On Sun's website (
http://java.sun.com/docs/books/tutorial/servlets/communication/request-dispatcher.html), they claim that when you do:
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page);
the RequestDispatcher will be null if the page doesn't exist. They even show a specific example where the check for null. I tried that, again, didn't work. In the simplest form:
if (dispatcher==null)
{
System.out.println("dispatcher null");
}
and got nothing.
Ideas, anyone? Thanks in advance!