Linux can';t自定义tomcat7 404错误页面
我正在尝试自定义tomcat7错误页面。我需要对所有上下文路径进行全局设置,因此我最终得到了global/etc/tomcat/web.xml文件中的配置:Linux can';t自定义tomcat7 404错误页面,linux,tomcat7,Linux,Tomcat7,我正在尝试自定义tomcat7错误页面。我需要对所有上下文路径进行全局设置,因此我最终得到了global/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:schemaLoc
<?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>
以及自定义错误页面的内容:
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>
cat/usr/share/tomcat7/webapps/ROOT/custom pages/error.jsp
很抱歉,找不到您请求的页面。
有什么想法吗?提前谢谢。好吧,同时我已经找到了答案。我不得不在/etc/tomcat7/context.xml中注释org.apache.catalina.valves.ErrorReportValve指令,它成功了。看起来此指令“覆盖”了任何自定义错误页!希望对其他人有用…:
<!--
<Valve className="org.apache.catalina.valves.ErrorReportValve"
showReport="false" showServerInfo="false" />
-->
您的结束标记将按预期顺序切换。可能是打字错误,不确定会不会影响任何事情,但值得注意<代码>应该是
嗨!是的,这是一个打字错误。无论如何,谢谢你注意到这一点。
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>
<!--
<Valve className="org.apache.catalina.valves.ErrorReportValve"
showReport="false" showServerInfo="false" />
-->