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>

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


---------------------
注意 : 删除tomcat的默认目录,只保留ROOT目录,并将ROOT目录的内容清空(rm -rf *) 用于存放error.html
原文:https://blog.csdn.net/qq_32523587/article/details/82110940

原文地址:https://www.cnblogs.com/yinyl/p/10518297.html