How to implement Exception Handling in a web-application. like if i get a nullpointer exception it should display a user friendly message instead of a stack trace of the error for the same. how to implement that?? please help.
[Vipassana] - It is seeing the reality as it is, And not as you want it to be.!!!
However, you might want to define a custom exception if there are special conditions or data values that will help you debug the cause. Then, in the web.xml define a handler that can extract these values and log them while sending an appropriate explanation to the user.
actually i wanted my application to handle that without using web.xml through code. so i thought of using filters but exception is not accessible there. how do i implement that. so if i say i got java.sql.SQLException it should print. a custom message instead of a stack trace. what should i use so that each and every page in my application has access to this feature?? please help..
Author and all-around good cowpoke
Joined: Mar 22, 2000
what should i use so that each and every page in my application has access to this feature??
The whole idea of the deployment descriptor (web.xml) is that information therein applies to the whole application. ;)
will this be applicable for the entire application or do i need to define errorPage in every jsp in my application.
If you declare the above in the DD, it applies to the entire application. ie, if "any" exception is encountered in "any" page then it is redirected to the "ErrorPage.jsp".
Note: you should declare <%@ page isErrorPage="true" %> in the ErrorPage.jsp if you want access to the default "session" object
For any specific JSP page, if you want to configure a "different" error page instead of the default ErrorPage.jsp, then you can specify it by using <%@page errorPage="relativeURL"%>. This declaration will override the default declaration in the DD..