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>

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

 
      • 原文地址:https://www.cnblogs.com/licz/p/11726613.html

posted @ 2022-08-23 21:13  李朋_Wechat  阅读(170)  评论(0编辑  收藏  举报