Custom Error Page in Tomcat 7 for Error Code 500

前端 未结 2 408
温柔的废话
温柔的废话 2020-12-16 13:30

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

相关标签:
2条回答
  • 2020-12-16 14:04

    The same can be implemented programmatically if you use embedded Tomcat for example like this:

            Context appContext = ...            
            ErrorPage errorPage = new ErrorPage();
            errorPage.setErrorCode(HttpServletResponse.SC_NOT_FOUND);
            errorPage.setLocation("/my_custom_error_page.html");
            appContext.addErrorPage(er);
    
    0 讨论(0)
  • 2020-12-16 14:14

    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>
    

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

    0 讨论(0)
提交回复
热议问题