gpt4 book ai didi

java - Tomcat 7 中错误代码 500 的自定义错误页面

转载 作者:太空狗 更新时间:2023-10-29 23:02:25 24 4
gpt4 key购买 nike

伙计们,我正在努力解决在 Windows 环境中的 Tomcat 中打开自定义错误页面的问题。我得到了一些解决方案,但没有运气。我尝试了几乎所有链接,但它对我不起作用。他们中的一些人为部署在 Tomcat 中的其他解决方案工作,但不为我的 Web 服务工作

我的 web.xml

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<error-page>
<location>/error.html</location>
</error-page>


我从我的 Servlet 3.0 应用程序发送错误response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

我已将我的 error.html 放在我的 WebService 的根目录中。

我尝试过的一些 JSP 页面链接而不是 HTML 链接

如果是 JSP,我使用:

<%@ page isErrorPage="true" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Error</h1>
</body>
</html>


仅供引用,它适用于其他 Tomcat 内置解决方案,它运行良好。但在我的 Webservice 中,我收到响应 500,但页面打开时空白。还有一件事我已经禁用了我的 Internet Explorer 9.0 显示错误友好页面仍然响应来自 servlet 500。但是错误页面变空了。

如果对我的查询有任何想法或疑问,请告诉我。我尽快需要它。

最佳答案

尝试将以下代码片段放入您的 WEB-INF/web.xml

<error-page>
<error-code>500</error-code>
<location>/Error.jsp</location>
</error-page>

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/Error.jsp</location>
</error-page>

在这种情况下,Error.jspWEB-INF 目录处于同一级别(不在其中)。

关于java - Tomcat 7 中错误代码 500 的自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15987212/

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