How to Set a Default Error Page in web.xml
In web.xml, you can use the
Servlet 3.0 or Newer
If you're using Servlet 3.0 or newer, you can simply add the following
<code class="xml"><web-app ...> <error-page> <location>/general-error.html</location> </error-page> </web-app></code>
Servlet 2.5
For Servlet 2.5, you need to specify each common HTTP error individually:
<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>
To summarize, for Servlet 3.0 or newer, you can set a default error page directly. For Servlet 2.5, you need to manually handle each common HTTP error using separate
The above is the detailed content of How to Set a Default Error Page in web.xml?. For more information, please follow other related articles on the PHP Chinese website!