Tomcat 配置错误界面

Tomcat发生错误时跳转到错误页面

一、修改 tomcat 的配置文件

修改 tomcat 的配置文件,当页面发生错误时跳转到指定的页面,在 tomcat 中 web.xml 文件中添加如下内容:

<!-- 400错误 -->  
<error-page>  
    <error-code>400</error-code>  
    <location>/error.html</location>  
</error-page>  
<!-- 404 页面不存在错误 -->  
<error-page>  
    <error-code>404</error-code>  
    <location>/error.html</location>  
</error-page>  
<!-- 500 服务器内部错误 -->  
<error-page>  
    <error-code>500</error-code>  
    <location>/error.html</location>  
</error-page>  
<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->  
<error-page>  
    <exception-type>java.lang.Exception</exception-type>  
    <location>/error.html</location>  
</error-page>  
<!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->  
<error-page>  
    <exception-type>java.lang.NullPointerException</exception-type>  
    <location>/error.html</location>  
</error-page>
二、编写 error.html 界面

error.html 界面需要放在 webapps 的 ROOT 目录中,结构如下:

这里写图片描述
404文件夹内容
404文件夹

error.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>网页访问不了</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="404/error_all.css?t=201303212934">
</head>
<body class="error-404">
<div id="doc_main">

    <section class="bd clearfix">
        <div class="module-error">
            <div class="error-main clearfix">
                <div class="label"></div>
                <div class="info">
                    <h3 class="title">啊哦,你所访问的页面不存在了,可能是炸了</h3>
                    <div class="reason">
                        <p>可能的原因:</p>
                        <p>1.手抖打错了。</p>
                        <p>2.链接过了保质期。</p>
                    </div>
                    <div class="oper">
                        <p><a href="javascript:history.go(-1);">返回上一级页面&gt;</a></p>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>

</body></html>

error_all.css

body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, textarea, select, optgroup, option, fieldset, legend, p, blockquote, th, td {
    margin:0;
    padding:0
}
fieldset, img {
    border:0
}
ul, li, ol {
    list-style:none
}
h1, h2, h3, h4, h5, h6 {
    font-size:100%
}
legend {
    color:#000
}
input, button, textarea, select, optgroup, option {
    font-family:inherit;
    font-size:inherit;
    font-style:inherit;
    font-weight:inherit
}
input, button, select {
    margin:0;
*font-size:100%;
    line-height:1.2
}
a img, img {
    -ms-interpolation-mode:bicubic
}
body {
    background:#FFF
}
a {
    color:#06c;
    text-decoration:none
}
a:hover, a:active, a:focus {
    color:#06c;
    text-decoration:underline
}
table {
    border-collapse:collapse;
    border-spacing:0
}
header, aside, section {
    display:block
}
body, button, input, select, textarea {
    font:12px/1.5 tahoma, arial, "微软雅黑";
    color:#666
}
.center {
    text-align:center
}
.clear:after, .clearfix:after {
    content:".";
    display:block;
    clear:both;
    visibility:hidden;
    font-size:0;
    height:0;
    line-height:0
}
.clear, .clearfix {
    zoom:1
}
.b-panel {
    position:absolute
}
.b-fr {
    float:right
}
.b-fl {
    float:left
}
.error-404 {
    background-color:#EDEDF0
}
.module-error {
    margin-top:182px
}
.module-error .error-main {
    margin:0 auto;
    width:420px
}
.module-error .label {
    float:left;
    width:160px;
    height:151px;
    background:url('error.png') 0 0 no-repeat
}
.module-error .info {
    margin-left:182px;
    line-height:1.8
}
.module-error .title {
    color:#666;
    font-size:14px
}
.module-error .reason {
    margin:8px 0 18px 0;
    color:#666
}

error.png
这里写图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值