error-page related to IndexOutOfBoundsException works fine.
But error-page related to is not sent to the client. If i use Tp.html instead of Tp.jsp
everything is fine. How to make jsp page work along with error-code. I am using tomcat 5.5.28
Thanks in advance
We will have a future if we save Nature!
Exception is thrown in out.print( exception.getMessage() ); , because exception object is null.
Why it is not able to get exception object.
Joined: Apr 21, 2008
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.
Joined: Dec 26, 2007
It was very nice and clear and neat explanation. Thanks to point out that error codes are different from exception. I was considering both same. Thank you very much.