How To Define Mistake Page Inward Coffee Spider Web Application - Servlet Jsp
There are ii ways to define Error page inwards 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 at that topographic point is whatsoever unhanded exception thrown from that page, corresponding mistake page volition last displayed. Second approach is an application broad full general or default mistake page which is shown if whatsoever Exception is thrown from whatsoever Servlet or JSP in addition to at that topographic point is no page specific mistake page defined.
Page Specific Error page inwards JSP
Every JSP page has an attribute called "errorpage" on page directive, past times using this attribute you lot tin define an mistake page for whatsoever detail JSP. After that if whatsoever unhandled Exception thrown from that JSP , this mistake page volition last invoked. In social club to brand whatsoever JSP page equally an mistake page you lot withdraw to piece of occupation "isErrorPage" attribute of page directive in addition to grade it true. For example inwards below JSP pages error.jsp is an mistake page which tin last used to display custom mistake messages if whatsoever unhandled exception is thrown from login.jsp (because it is defined equally errorpage for login.jsp)
//error.jsp
<%@ page isErrorPage="true"%>
//login.jsp
<%@ page errorPage="error.jsp"%>
This is preferred agency of showing mistake messages inwards Java spider web application if you lot direct maintain custom mistake messages based on JSP in addition to it besides replace whatsoever application broad mistake page defined inwards web.xml.
Error page inwards Java Web Application JSP Servlet
Application broad Error page inwards Java spider web application
There is only about other agency to define mistake pages inwards 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 whatsoever detail servlet or JSP. Its recommended practise for every Java spider web application to direct maintain a default mistake page inwards addtion of page specific mistake pages. This mistake page is defined inwards web.xml past times using tag <error-page>. <error-page> allows you lot to define custom mistake message based upon HTTP mistake code or whatsoever Java Exception. you lot tin define a default mistake message for all exception past times specifying <exception-type> equally java.lang.Throwable in addition to it would last applicable to all exception thrown cast whatsoever Servlet or JSP from spider web application. hither is an example of declaring default mistake page inwards 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 inwards Java application both page specific in addition to an application broad default mistake page.Important indicate to banking concern annotation is that page specific mistake pages takes precedence over application broad default mistake page defined inwards web.xml.
Further Learning
Spring Framework 5: Beginner to Guru
How to piece of occupation load-on-startup tag inwards web.xml to meliorate reply time.
Komentar
Posting Komentar