gpt4 book ai didi

linux - 无法自定义tomcat7 404错误页面

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:08 27 4
gpt4 key购买 nike

我正在尝试自定义 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>

然而,当我请求一些不存在的页面时,我得到一个默认的错误页面,但不是我的页面:

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 网络目录的布局:

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>

有什么想法吗?提前致谢。

最佳答案

好吧,同时我找到了答案。我不得不在 /etc/tomcat7/context.xml 中注释 org.apache.catalina.valves.ErrorReportValve 指令,它成功了。看起来这个指令“覆盖”了任何自定义错误页面!希望对其他人有用......:

<!-- 
<Valve className="org.apache.catalina.valves.ErrorReportValve"
showReport="false" showServerInfo="false" />
-->

关于linux - 无法自定义tomcat7 404错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44052425/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com