GlobalWinner
asked on
JSP & Throwing Errors to an 'Error Page'
I have the following code in an 'Error Page' JSP file.
When throwing an error e.g. Null Pointer, ODBC Error, any other exception that is thrown, it is displayed.
Is there code to display a more user friendly error? e.g.
If Null.Pointer is displayed instead show: 'Blank Variable'
If ODBC Error displayed instead show 'Database Connection Error'?
When throwing an error e.g. Null Pointer, ODBC Error, any other exception that is thrown, it is displayed.
Is there code to display a more user friendly error? e.g.
If Null.Pointer is displayed instead show: 'Blank Variable'
If ODBC Error displayed instead show 'Database Connection Error'?
<%@ page isErrorPage="true" %> //Page Type
exception.toString() //Exception Caught & Displayed
ASKER
Unfortunately I need to have the JSP handle the code, I can only use 1 JSP error page.
>I can only use 1 JSP error page.
Ok, you can use something like
Ok, you can use something like
<%@page isErrorPage="true" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:if test="${pageContext.errorData.throwable == 'java.lang.NullPointerException'}">
'Blank Variable was entered' <br/>
</c:if>
<c:if test="${pageContext.errorData.throwable == 'ODBC Error type'}">
'Database Connection Error' <br/>
</c:if>
Also the following properties are available. <br/>
requestURI is ${pageContext.errorData.requestURI} <br/>
statusCode is ${pageContext.errorData.statusCode}
Soory I assumed that you are using JSTL 1.1+
If not then can you translate to scriptlet ?
If not then can you translate to scriptlet ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your Brilliant! Worked a treat :D
Something like
<error-page>
<exception-type>java.lang.
<location>/myNullMessage.j
</error-page>
or
<error-page>
<error-code>404</error-cod
<location>/myNotFound.jsp<
</error-page>
Look at
http://publib.boulder.ibm.com/infocenter/wchelp/v6r0m0/topic/com.ibm.commerce.developer.doc/concepts/csdjsperror.htm