Exception handling in Servlet
Exception Handling is one of important activity for any web application. If we do not implemented proper exception handling in the web application then application can crash and end user may be confused.
Servlet API provides support for custom Exception and Error Handler servlets that we can configure in
deployment descriptor. The whole purpose of these servlets are to handle the Exception or Error raised by application and send useful HTML response to user.
Exception Handling Example :-
Exception Generated by container :-
When user access the servlet by using url-pattern as shown in below image address bar them he will see the error message as shown below.
Servlet Exception and Error Handling :-
Servlet API have support for custom Exception and Error Handler servlets that we can configure in deployment descriptor(web.xml).
Here we want to show meaning full massage to end user instead of showing default error message coming from servlet container.