posted 15 years ago
Hi, Sharmila.
Error codes are not exception's. If our error generated jsp, causes error code 403, then container/server first checks, is there any errorPage directive declared to handle that error? If no, then approaches the web.xml's <error-page> entry, then checks the <error-code>, and if matching found, serves the page. In Tp.jsp, we have declared means the exception implicit object will be available to this jsp. Since there is no exception generated in our error genearated jsp, here exception point's to 'null'. Calling getMessage() on null produces 'NullPointerException'.
Incase of exception generated jsp, if there is any exception generated in the code like (calling 10/0), then container creates exception object(here it is ArithematicException Object) and cathes it. In the catch block it calls the PageContext's handlePageException(t) method by passing the exception object. Then this method will checks is there any 'errorPage' directive declared in the jsp? If yes forward's the request to that jsp. If no, then it approaches the web.xml's <error-page> entry and checks the appropriate exception-type and forwards the request to it. If that page has declared then exception implicit object will be available to the jsp and that exception object is not 'null', since we got 'ArithematicException' in the exception generated jsp and calling getMessage() on it gives '/zero' message.
To be clear see the generated source code and the api of PageContext's handlePageException() method.
SCJP5.0, SCWCD5.0, OCEJPAD6, OCPJWSD6