Not able to configure Error Page?

Customers have often reported issues that they are not able to configure error page even though the do the configuration in the web.xml correctly

web.xml
<?xml version=’1.0′ encoding=’UTF-8′?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<display-name>TestApplication</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/error.jsp</location>
</error-page>
</web-app>

error.jsp

<%@page isErrorPage=”true” contentType=”text/html” %>
<html>
<body>
Request that failed: ${pageContext.errorData.requestURI}
<br />
Status code: ${pageContext.errorData.statusCode}
<br />
Exception: ${pageContext.errorData.throwable}
<br />
${pageContext.errorData.servletName}
</body>
</html>
index.jsp
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<%
String s = null;
out.println(s.trim());
%>
</BODY>
</HTML>

When I deployed this application on Weblogic Server and tried to acces the application. I got null pointer exception causing server to send HTTP 500 Response
with Exception

java.lang.NullPointerException
at jsp_servlet.__index._jspService(__index.java:76)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run
(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecuri
tyHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.jav
a:292)
Truncated. see log file for complete stacktrace

But since we had done the error page configuration, we expected to see our custom error page. This was not the case.
We saw the following. ( Note I was using IE 7)



I had to do the following configuration change on IE to get it working. ( Uncheck Show Friendly HTTP Error Messages)



After changing the IE Setting, I was able to get the custom error page.


Reference :-

http://www.java2s.com

4 comments

  1. Hi,

    why don’t you use web server to configure error page, instead of configuring in web.xml. if it is configured in web server it very easy to access than application server. performance wise also it is good practice

    Regards,
    Ravi Kumar Guduru

    1. Thanks for you suggestion Ravi.
      Yes its convenient to configure the error page on the web server end, however there are scenarios where there are no Web Servers infront of WLS.
      Then this technique can be applied.

  2. Increase the size of the error.jsp to more than 1KB and the error page will show up without changing the IE option. If the size is less 1KB IE thinks it is the standard HTTP error from the web server and replaces with its own supposed to be friendly error message page. Increasing the size of the .jsp from 1KB to 5KB worked for me. Added some random text within

Leave a Reply