【问题标题】:Suppress 500 error stacktrace in Tomcat抑制 Tomcat 中的 500 错误堆栈跟踪
【发布时间】:2017-10-14 08:13:18
【问题描述】:

我想在 500 内部服务器发生时抑制 tomcat 显示的堆栈跟踪。我已经包含了一个自定义 error.html 页面,并在 web.xml 中提到了文件位置和错误代码。

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

进行上述更改后,对于所有 API 的 tomcat 都返回 404 Not Found。

【问题讨论】:

    标签: tomcat error-handling


    【解决方案1】:

    web.xml 中,添加如下内容:

    <error-page>
        <error-code>400</error-code>
        <location>/WEB-INF/jsp/errorpages/ErrorPage400.jsp</location>
    </error-page>
    <error-page>
        <error-code>401</error-code>
        <location>/WEB-INF/jsp/errorpages/ErrorPage401.jsp</location>
    </error-page>
    <error-page>
        <error-code>403</error-code>
        <location>/WEB-INF/jsp/errorpages/ErrorPage403.jsp</location>
    </error-page>
    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/jsp/errorpages/ErrorPage404.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/WEB-INF/html/error.html</location>
    </error-page>
    



    HTML 文件的路径应类似于 /WEB-INF/html/error.html

    【讨论】:

    • 添加后,返回For 500 Internal server error 404 Not Found,正文为空。
    猜你喜欢
    • 2023-04-05
    • 2013-05-30
    • 2018-09-19
    • 1970-01-01
    • 2013-09-29
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多