web.xml配置404,500自定义错误页面无效的解决办法

在IE下总显示IE提供的“友好的错误提示”

可以关闭

IE--工具--Internet选项--高级--取消勾选 显示友好 http 错误消息

想显示自己的错误提示,总不能期望客户把这个关上,

IE在响应内容小于一定阈值的情况下会显示友好的错误提示,

解决办法就是充实一下页面,让大小超过512即可

下面列出一张表供大家参考:

代码描述文件大小(阈值)
400Bad Request> 512 bytes
403Forbidden> 256 bytes
404Not Found> 512 bytes
405Method Not Allowed> 256 bytes
406Not Acceptable> 512 bytes
408Request Time-out> 512 bytes
409Conflict> 512 bytes
410Gone> 256 bytes
500Internal Server Error> 512 bytes
501Not Implemented> 512 bytes
505HTTP Version Not Supported> 512 bytes

    <error-page>  
        <error-code>403</error-code>  
        <location>/WEB-INF/jsp/error/403.jsp</location>  
    </error-page>
  	<error-page>  
        <error-code>404</error-code>  
        <location>/WEB-INF/jsp/error/404.jsp</location>  
    </error-page>
    <error-page>  
        <error-code>500</error-code>  
        <location>/WEB-INF/jsp/error/500.jsp</location>  
    </error-page>

    <!-- java.lang.Exception -->  
    <error-page>  
        <exception-type>java.lang.Exception</exception-type>  
        <location>/error.jsp</location>  
    </error-page>
    <!-- java.lang.NullPointerException -->  
    <error-page>    
        <exception-type>java.lang.NullPointerException </exception-type>    
        <location>/error.jsp</location>    
    </error-page>

404.jsp样例

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>无法找到文件</title>
</head>
<body>
对不起,页面未找到!
<!-- Ticket #11289, IE bug fix: always pad the error page with enough characters
such that it is greater than 512 bytes, even after gzip compression
abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuu
vvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmln
mnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz
1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx
1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3
dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5
dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono -->
</body>
</html>

参考:

解决IE下自定义HTTP错误页太小不显示并导致显示默认友好错误页问题 - Wang Ye / 王 晔

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值