Tomcat 7中针对错误代码500的自定义错误页面

伙计们,我在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内置解决方案,它运行正常。但是在我的 Web服务中, 我得到响应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.jsp,它与WEB-INF目录处于同一级别(不在目录之内)。

以上是 Tomcat 7中针对错误代码500的自定义错误页面 的全部内容, 来源链接: utcz.com/qa/420952.html

回到顶部