简体   繁体   English

Tomcat 7中的自定义错误页面,用于错误代码500

[英]Custom Error Page in Tomcat 7 for Error Code 500

Guys I am struggling with the problem of opening my custom error page in Tomcat in Windows Environment. 伙计们我正在努力解决在Windows环境中在Tomcat中打开自定义错误页面的问题。 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 其中一些用于Tomcat中部署的其他解决方案,但不适用于我的Web服务

My web.xml 我的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>


I am sending error from my Servlet 3.0 Application response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 我从我的Servlet 3.0应用程序response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);发送错误response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

I have put my error.html in the root directory of my WebService. 我把我的error.html放在我的WebService的根目录中。

Some of the links I got for JSP page instead of HTML that also I have tried 我为JSP页面而不是HTML获得的一些链接也是我尝试过的

In case of JSP I used: 在我使用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>


FYI it is working fine for other Tomcat inbuilt solution it's working perfectly. 仅供参考,它适用于其他Tomcat内置解决方案,它运行良好。 But in my Webservice I am getting response 500 but page is opening blank. 但是在我的Web服务中,我得到了响应500,但页面空白。 And one other thing I have disabled my Internet Explorer 9.0 show error friendly page still response coming 500 from servlet. 另一件事我禁用了我的Internet Explorer 9.0显示错误友好页面仍然响应来自servlet 500。 But error page is coming empty. 但是错误页面是空的。

If any idea or any doubt about my query just let me know. 如果对我的查询有任何想法或疑问,请告诉我。 I need it ASAP. 我尽快需要它。

Try putting the following snippet in your WEB-INF/web.xml 尝试将以下代码段放在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>

In this case Error.jsp is at the same level as WEB-INF directory (not inside it). 在这种情况下, Error.jspWEB-INF目录处于同一级别(不在其中)。

The same can be implemented programmatically if you use embedded Tomcat for example like this: 如果您使用嵌入式Tomcat,则可以通过编程方式实现相同的功能,例如:

        Context appContext = ...            
        ErrorPage errorPage = new ErrorPage();
        errorPage.setErrorCode(HttpServletResponse.SC_NOT_FOUND);
        errorPage.setLocation("/my_custom_error_page.html");
        appContext.addErrorPage(er);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM