Internet Explorer 中未显示自定义 HTTP 错误页面 [英] Custom HTTP error page is not displayed in Internet Explorer

查看:32
本文介绍了Internet Explorer 中未显示自定义 HTTP 错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Tomcat 7 和 JSP 页面.我想为 HTTP 500 错误提供自定义错误页面.

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

我所做的是在web.xml中声明自定义错误页面如下:

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>

我创建了一个名为 error.jsp 的 JSP,代码如下:

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>

现在这适用于大多数浏览器,但在 Internet Explorer 中,我被带到标准的网站无法显示页面"页面.

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

为什么我的自定义 HTTP 500 错误页面没有显示在 Internet Explorer 中?

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

推荐答案

这是一个 IE 功能.当从服务器检索到的 HTTP 错误页面小于 512 字节时,IE 将默认显示一个友好"错误页面,就像您所面临的那样,可以通过 工具 > Internet 选项 > 高级 > 取消选中来配置在浏览器中显示友好错误消息".其他(真实的)浏览器没有这个功能.

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.

使您的 HTTP 错误页面略大于 512 字节应该可以解决此 IE 功能.您可以添加一些额外的元标题、添加一些空格来缩进代码、按照网站的标准布局添加更多语义标记、添加大的 HTML 注释等.

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.

这篇关于Internet Explorer 中未显示自定义 HTTP 错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆