zoukankan      html  css  js  c++  java
  • tomcat自定义错误页面

    当我们访问tomcat的一个不存在的页面,返回错误信息如下:

     

    这样的界面直接暴露给用户并不友好,有时候还不安全,因此一般需要修改默认的错误页。

    vim /$TOMCAT_HOME/conf/web.xml

    在文件末尾,</web-app>的前面,加上以下内容:

    <error-page>
    <error-code>400</error-code>
    <location>/error.html</location>
    </error-page>
    
    <error-page>
    <error-code>404</error-code>
    <location>/error.html</location>
    </error-page>
    <error-page>
    <error-code>500</error-code>
    <location>/error.html</location>
    </error-page>
     

     例:

    在/$TOMCAT_HOME/webapps/ROOT目录下添加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>
    </div>
    </div>
    </section>
    </div>
    
    </body></html>

    再次打开一个不存在的界面,显示如下:

  • 相关阅读:
    SVG ViewBox
    svg中改变class调用的线条颜色
    SVG 箭头线绘制
    Spring3中的mvc:interceptors标签配置拦截器
    MyBatis入门学习
    MyBatis 配置sql语句输出
    使用iBATIS3.0完成增删改查
    iBatis简单入门教程
    SpringMVC常用注解,返回方式,路径匹配形式,验证
    springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
  • 原文地址:https://www.cnblogs.com/licz/p/11726613.html
Copyright © 2011-2022 走看看