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

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

可以关闭

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

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

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

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

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

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

参考:

http://wangye.org/blog/archives/559/

猜你喜欢

转载自happyqing.iteye.com/blog/2196958
今日推荐