How To Define Fault Page Inward Coffee Spider Web Application - Servlet Jsp
There are 2 ways to define Error page inward Java spider web application written using Servlet in addition to JSP. First agency is page wise mistake page which is defined on each jsp page in addition to if in that place is whatever unhanded exception thrown from that page, corresponding mistake page volition hold upwardly displayed. Second approach is an application broad full general or default mistake page which is shown if whatever Exception is thrown from whatever Servlet or JSP in addition to in that place is no page specific mistake page defined.
Page Specific Error page inward JSP
Every JSP page has an attribute called "errorpage" on page directive, past times using this attribute y'all tin dismiss define an mistake page for whatever item JSP. After that if whatever unhandled Exception thrown from that JSP , this mistake page volition hold upwardly invoked. In lodge to brand whatever JSP page every bit an mistake page y'all ask to piece of job "isErrorPage" attribute of page directive in addition to score it true. For illustration inward below JSP pages error.jsp is an mistake page which tin dismiss hold upwardly used to display custom mistake messages if whatever unhandled exception is thrown from login.jsp (because it is defined every bit errorpage for login.jsp)
//error.jsp
<%@ page isErrorPage="true"%>
//login.jsp
<%@ page errorPage="error.jsp"%>
This is preferred agency of showing mistake messages inward Java spider web application if y'all receive got custom mistake messages based on JSP in addition to it likewise supplant whatever application broad mistake page defined inward web.xml.
Error page inward Java Web Application JSP Servlet
Application broad Error page inward Java spider web application
There is roughly other agency to define mistake pages inward coffee spider web application written using servlet in addition to JSP. This is called application broad mistake page or default/general mistake page because its applicable to whole spider web application instead of whatever item servlet or JSP. Its recommended do for every Java spider web application to receive got a default mistake page inward addtion of page specific mistake pages. This mistake page is defined inward web.xml past times using tag <error-page>. <error-page> allows y'all to define custom mistake message based upon HTTP mistake code or whatever Java Exception. y'all tin dismiss define a default mistake message for all exception past times specifying <exception-type> every bit java.lang.Throwable in addition to it would hold upwardly applicable to all exception thrown cast whatever Servlet or JSP from spider web application. hither is an illustration of declaring default mistake page inward Java spider web application based on HTTP Error code in addition to Java Exception type.
Default Error page based on Exception type:
<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>
That's all on how to define custom mistake page inward Java application both page specific in addition to an application broad default mistake page.Important cry for to complaint is that page specific mistake pages takes precedence over application broad default mistake page defined inward web.xml.
Further Learning
Spring Framework 5: Beginner to Guru
How to piece of job load-on-startup tag inward web.xml to ameliorate answer time.
0 Response to "How To Define Fault Page Inward Coffee Spider Web Application - Servlet Jsp"
Post a Comment