Tomcat 7中的自定义错误页面,用于错误代码500 [英] Custom Error Page in Tomcat 7 for Error Code 500

查看:628
本文介绍了Tomcat 7中的自定义错误页面,用于错误代码500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Guys I am struggling with the problem of opening my custom error page in Tomcat in Windows Environment. Some of solution I got but no luck. I tried almost all links but its not working for me. Some of them working for other solution deployed in Tomcat but not for my Web Service

我的 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的根目录中。

I have put my error.html in the root directory of my WebService.

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

Some of the links I got for JSP page instead of HTML that also I have tried

如果我使用的是JSP:

In case of JSP I used:

<%@ 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。但是错误页面是空的。


FYI it is working fine for other Tomcat inbuilt solution it's working perfectly. But in my Webservice I am getting response 500 but page is opening blank. And one other thing I have disabled my Internet Explorer 9.0 show error friendly page still response coming 500 from servlet. But error page is coming empty.

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

If any idea or any doubt about my query just let me know. I need it ASAP.

推荐答案

尝试将以下代码段放在 WEB-INF / web.xml中

Try putting the following snippet in your 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 目录(不在其中)相同的级别。

In this case Error.jsp is at the same level as WEB-INF directory (not inside it).

这篇关于Tomcat 7中的自定义错误页面,用于错误代码500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆