How to Specify a Default Error Page in web.xml
In web.xml, the
For Servlet 3.0 and above, the fix is simple:
<code class="xml"><web-app ...> <error-page> <location>/general-error.html</location> </error-page> </web-app></code>
For Servlet 2.5, where this feature is absent, the solution lies in explicitly defining common HTTP errors that users might encounter:
<code class="xml"><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></code>
This approach ensures that common errors are handled gracefully with custom error pages, providing a better user experience.
The above is the detailed content of How do I specify a default error page in web.xml for unhandled exceptions?. For more information, please follow other related articles on the PHP Chinese website!