File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes error-page with error-code and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "error-page with error-code and jsp" Watch "error-page with error-code and jsp" New topic
Author

error-page with error-code and jsp

Sharmila Punde
Ranch Hand

Joined: Dec 26, 2007
Posts: 133
Hi All,
I have web.xml as -

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
Regards


Regards, Sharmila.
We will have a future if we save Nature!
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Sharmila.

Can you please post, what message you are getting when trying to access error generated page?
Sharmila Punde
Ranch Hand

Joined: Dec 26, 2007
Posts: 133
Thanks Chinmaya
Tp.jsp code is as bellow -
java.lang.NullPointerException
at org.apache.jsp.Tp$jsp._jspService(Tp$jsp.java:59)

Exception is thrown in out.print( exception.getMessage() ); , because exception object is null.
Why it is not able to get exception object.
Regards

Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
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.
Sharmila Punde
Ranch Hand

Joined: Dec 26, 2007
Posts: 133
Thanks Chinmaya,
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.
Regards

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error-page with error-code and jsp
 
Similar Threads
How to handle JSP exceptions declaratively
handle exception in servlet
How to generate HTTP 4xx errors from within the application ?
response.sendError & error-page
welcome-file-list