hey buddy @Luigi Giuseppe. I thing this one will be going to satisfying for you doubt.
Two ways to define Error page in Java web application written using Servlet and JSP like your question related.
1. First way is page wise error page which is defined on each jsp page and if there is any unhanded exception thrown from that page, corresponding error page will be displayed.
2. Second approach is an application wide general or default error page which is shown if any Exception is thrown from any Servlet or JSP and there is no page specific error page defined.
HTTP standard error codes:
1. Information This one is a new return code which is not 100%
supported and normally and only provides information to the client
about the request.
2. Success response, the request has been correctly executed ->
expected answer from server (http code 200).
3. Redirection response. The resource has moved and is not any more at
this URL.
4. Error on client side. Probably most known of all is error 404 : Not
Found.
Defining error.jsp page like:
//error.jsp
<%@ page isErrorPage="true"%>
//login.jsp
<%@ page errorPage="error.jsp"%>
And, Error page in Java Web Application JSP Servlet page is like:
Default Error page based on Exception:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.htm</location>
</error-page>
Default Error page based on HTTP Error code:
<error-page>
<error-code>500</error-code>
<location>/internal-server-error.htm</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/page-not-found-error.htm</location>
</error-page>
Create your custom error pages:
1. 400.html -> telling the user did something wrong
2. 500.html -> telling the server did something wrong
400.html:
<error-page>
<error-code>400</error-code>
<location>/404.html</location>
</error-page>
<error-page>
<error-code>401</error-code>
<location>/404.html</location>
</error-page>
500.html:
<error-page>
<error-code>500</error-code>
<location>/500.html</location>
</error-page>
<error-page>
<error-code>501</error-code>
<location>/500.html</location>
</error-page>