在 Servlet 3.0 或更高版本上,您可以指定
<web-app ...>
<error-page>
<location>/general-error.html</location>
</error-page>
</web-app>
但是由于您仍在使用 Servlet 2.5,因此除了单独指定每个常见的 HTTP 错误之外别无他法。您需要确定最终用户可能面临哪些 HTTP 错误。在准系统 web 应用程序上,例如使用 HTTP 身份验证、禁用目录列表、使用可能引发未处理异常或未实现所有方法的自定义 servlet 和代码,然后您希望将其设置为 HTTP 错误 401 , 403, 500 和 503。
<error-page>
<!-- Missing login -->
<error-code>401</error-code>
<location>/general-error.html</location>
</error-page>
<error-page>
<!-- Forbidden directory listing -->
<error-code>403</error-code>
<location>/general-error.html</location>
</error-page>
<error-page>
<!-- Missing resource -->
<error-code>404</error-code>
<location>/Error404.html</location>
</error-page>
<error-page>
<!-- Uncaught exception -->
<error-code>500</error-code>
<location>/general-error.html</location>
</error-page>
<error-page>
<!-- Unsupported servlet method -->
<error-code>503</error-code>
<location>/general-error.html</location>
</error-page>
这应该涵盖最常见的那些。