10

I am using Tomcat 7 and JSP pages. I would like to provide a custom error page for HTTP 500 errors.

What I did is to declare the custom error page as following in web.xml:

<error-page>
  <error-code>500</error-code>
  <location>/error.jsp</location>
</error-page>

And I created a JSP called error.jsp with the following code:

<%@ page pageEncoding="UTF-8" isErrorPage="true" %>
<!DOCTYPE html>
<html>
  <head>
    <title>500</title>
  </head>
  <body>
    <img src="${pageContext.request.contextPath}/images/500.jpg" />
  </body>
</html>

Now this works in most browsers, but in Internet Explorer I am taken to the standard "The website cannot display the page" page.

Why is my custom HTTP 500 error page not being displayed in Internet Explorer?

2 Answers 2

31

This is an IE feature. When an HTTP error page retrieved from the server is smaller than 512 bytes, then IE will by default show a "Friendly" error page like the one you're facing, which is configureable by Tools > Internet Options > Advanced > Uncheck "Show Friendly Error Message" in the browser. Other (real) browsers does not have this feature.

Making your HTTP error page a little larger than 512 bytes should workaround this IE feature. You could add some extra meta headers, add some whitespace to indent code, add some more semantic markup following your site's standard layout, add a large HTML comment, etc.

1
  • Yes. Even I had to do this to fix my issue . But all the data got displayed properly except tab icon. It is showing default tomcat icon. Mine is a simple html page. Any solution? Oct 27, 2017 at 4:33
-1

Found that adding

<% response.setStatus(200); %>

to the error JSP page (i.e. before HTML tag) would fix the issue.

2
  • my problem with tab icon got solved by setting response status to 200. Thanx Oct 30, 2017 at 9:01
  • 1
    So this solution to IE not rendering a custom 500 response page… is to return all 500 response pages as 200. That will definitely cause issues for anything that expects a meaningful status code to indicate an error. Jun 16, 2021 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.