Tomcat错误页重定向(应用程序错误消息)

当Tomcat出现404、400等界面之后跳转到默认页

1、创建新的错误页

编写新的界面error.html,将此界面放到 tomcat6/webapps/ROOT 目录下

2、创建编写web.xml

修改Tomcat/webapps/ROOT/WEB-INF/web.xml文件内容,指定错误状态码对应的界面

<?xml version="1.0" encoding="utf-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee                       http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true">  
  <display-name>Welcome to Tomcat</display-name>  
  <description>Welcome to Tomcat</description>  
  <error-page> 
    <error-code>404</error-code>  
    <location>/error.html</location> 
  </error-page>  
  <error-page> 
    <error-code>400</error-code>  
    <location>/error.html</location> 
  </error-page>  
  <error-page> 
    <error-code>500</error-code>  
    <location>/error.html</location> 
  </error-page> 
</web-app>

 

posted @ 2022-11-30 11:44  浪淘沙&  阅读(488)  评论(0编辑  收藏  举报