Link to home
Start Free TrialLog in
Avatar of GlobalWinner
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'?
<%@ page isErrorPage="true" %> //Page Type
 
 exception.toString() //Exception Caught & Displayed

Open in new window

Avatar of rrz
rrz
Flag of United States of America image

You can edit your web app's web.xml file to control this at application level.
Something like  
<error-page>
                     <exception-type>java.lang.NullPointerException</exception>
                     <location>/myNullMessage.jsp</location>
</error-page>
or
<error-page>
                     <error-code>404</error-code>
                     <location>/myNotFound.jsp</location>
</error-page>
Look at
http://publib.boulder.ibm.com/infocenter/wchelp/v6r0m0/topic/com.ibm.commerce.developer.doc/concepts/csdjsperror.htm   
Avatar of GlobalWinner
GlobalWinner

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  
<%@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}

Open in new window

Soory I assumed that you are using  JSTL 1.1+
If not then can you translate to scriptlet ?
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your Brilliant! Worked a treat :D