配置tomcat的404页

                     

              实现:当访问某个域名下不存在的服务时,也不会报错,不会将服务器的相关信息显示在客户端。一是为了安全。二是为了交互友好,美观。

                例如访问不存在的http://www.baidu.com/xyz,客户端也不会显示错误信息,而是跳转到一个错误页。

第一步: apache-tomcat/conf/web.html指定如下内容:
<error-page> 
   <error-code>404</error-code>  
   <location>/error.html</location>  
</error-page>
第二步:在tomcat的主目录下面,在webapp下的ROOT目录,新建error.html文件。文件内容如下
<html>
<head>
<meta http-equiv="Content-Language" content="zh-CN">
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<meta http-equiv="refresh" content="0.1;url=https://www.baidu.com/search/error.html">
<title></title>
</head>
<body>
</body>
</html>
就会自动跳转到:https://www.baidu.com/search/error.html

猜你喜欢

转载自blog.csdn.net/weixin_36087172/article/details/76671572
今日推荐