我正在尝试自定义tomcat7错误页面。我需要对所有上下文路径进行全局设置,因此我最终获得了全局/etc/tomcat/web.xml文件中的配置:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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">
<error-page>
<error-code>404</error-code>
<location>/custom-pages/error.jsp</location>
</error-page>
当我问它时,Tomcat成功地返回了页面:
curl -s 127.0.0.1:8080/custom-pages/error.jsp
<html><body>Sorry, the page you requested were not found.</html></body>但是,当我请求某个不存在的页面时,我会得到一个默认的错误页面,它附带了tomcat,但没有我的页面:
curl 127.0.0.1:8080/not-exist
<html><head><title>Error report</title></head>
<body><h1>HTTP Status 404 - /not-exist</h1></body>
</html>下面是tomcat web目录的布局:
tree /usr/share/tomcat7/webapps/
/usr/share/tomcat7/webapps/
└── ROOT
└── custom-pages
└── error.jsp以及自定义错误页面的内容:
cat /usr/share/tomcat7/webapps/ROOT/custom-pages/error.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html><body>Sorry, the page you requested were not found.</body></html>有什么想法吗?提前谢谢。
发布于 2017-05-19 10:19:21
同时我找到了答案。我不得不在org.apache.catalina.valves.ErrorReportValve内部评论/etc/tomcat7/context.xml指令,它做到了这一点。看起来这个指令“重写”了任何自定义错误页面!希望对其他人有用.
<!--
<Valve className="org.apache.catalina.valves.ErrorReportValve"
showReport="false" showServerInfo="false" />
-->https://stackoverflow.com/questions/44052425
复制相似问题