This tag specifies the HTTP error code which will trigger this error page.

Useful Error Codes

  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden (Authorization required)
  • 404 Not Found
  • 500 Internal Server Error
  • 503 Service Unavailable

Example for catching 404 errors (page not found)

<!-- Define an error handler for 404 pages --> 


  • Status code 500 is used when an unhandled exception occurs in the application. This kind of error can be handled in more detail using the <exception-type> directive. However, certain errors such as Struts "No action instance for path /somePath could be created" errors only return a 500 error code. They do not throw a Throwable. It is therefore good practise to catch 500 errors as well as Throwables.
  • If defining a global error handler, it is still good practise to include an <exception-type> handler to catch java.lang.Throwable exceptions, as well as handlers for error codes 500 and 503. This is because the detail of the error is lower when caught as 500/503. For example, you may be able to detect a ServletException, but not the NumberFormatException that really caused the error.
  • Handling of exceptions takes precedance over handling of error codes. ie: if an exception is thrown, and available, it will be passed to the exception handler. If no <exception-type> handler is present, a 500/503 will be generated, and that will be passed to any available <error-code> handler.
  • You will not normally want to catch 401 error codes. These are generated when Authorization is requested by the server (a password is requested in a popup dialog box). If caught, the user will be presented with your custom error page instead of the login request.

See Also

metawerx specific

referring pages