Servlet Exception Handling and servlet Exception Handling
When a Servlet throws an exception, the Web Container searches for the configuration that matches the thrown exception type in the web. xml that uses the exception-type element.
The premise is that it must be used in web. xmlError-pageElement to specify the Servlet call for a specific exception or HTTP status code.
<! -- Servlet definition --> <servlet-name> ErrorHandler </servlet-name> <servlet-class> ErrorHandler </servlet-class> </servlet> <! -- Servlet ing --> <servlet-mapping> <servlet-name> ErrorHandler </servlet-name> <url-pattern>/ErrorHandler </url-pattern> </servlet-mapping> <! -- Error-code-related error page --> <error-page> <error-code> 404 </error-code> <location>/ErrorHandler </location> </error- page> <! -- Error page related to exception-type --> <error-page> <exception-type> java. io. IOException </exception-type> <location>/ErrorHandler </location> </error-page>