Coding⏱️ 3 min read📅 2026-06-04

How to Fix: How to specify the default error page in web.xml?

Specify default error page in web.xml using error-type element

Quick Answer: {

The issue at hand is that you are using the element in web.xml to specify a friendly error page, but you want to display a default error page if no specific error code matches.

This can be frustrating for users who expect a standard error message instead of a custom one.

⚠️ Common Causes

  • The primary cause of this issue is that the element in web.xml only specifies a default page to display when a specific error code is matched. If no matching error code is found, the default web error page will be displayed instead.
  • However, if you want to specify a custom friendly error page for all error codes, including those not specified in the element, you'll need to use an alternative approach.

🔧 Proven Troubleshooting Steps

Specify a catch-all error handler using the element

  1. Step 1: Add a new element to your web.xml file with a wildcard error code (e.g., '*)' that points to your desired default error page.
  2. Step 2: This will ensure that any unhandled errors are redirected to the specified default error page.

Use a servlet or filter to handle all unhandled exceptions

  1. Step 1: Create a new servlet or filter that catches all unhandled exceptions and redirects them to your desired default error page.
  2. Step 2: This approach provides more flexibility, but it requires additional coding effort.

💡 Conclusion

To resolve the issue, you can use either the element or create a custom servlet/filter to handle all unhandled exceptions. Both methods will display your desired default error page when no specific error code matches.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions