Error Pages
ErrorPages configurations( Exception Handling configurations in JSP)
-->The page that executes only when exception is raised in jsp is called errorPage. It is useful to display non technical guiding messages to end user when exception is raised
-->There are 2 types of error pages configurations in jsp
a.)Local Error Page configuration
-->Using errorPage, isErrorPage attributes( <%@page%>)
-->Specific to one jsp page
b.)Global Error Page configuration
-->Using <error-page> tags of web.xml file)
-->Common for all jsp page of web applications
a.)Local Error page configuration
-->The error page (err.jsp) executes only when the exception is raised in main.jsp to display non-technical guiding messages to end user when exception is raised
- JspApp4-LocalErrorPage
- |-->webContent
- |-->main.jsp
- |-->err.jsp
main.jsp
- <%@page errorPage="err.jsp"%>
- <b>from main.jsp</b>
- <% int a=integer.parseInt("a10");%>
- Value is:- <%=a%>
err.jsp
- <%@page isErrorPage="true"%>
- <p>internal problem </p>
- <hr>
- <%=exception%>
-->Gives request to main.jsp
-->The implicit object exception is visible only in error jsp page and it can be used to display exception related messages as non technical guiding messages
b.)Global Error page configuration
-->Common for all the jsp pages of web application, must configurations in web.xml file
- JspApp5-GlobalErrorPage
- |-->webContent
- |-->main.jsp
- |-->err.jsp
- |-->WEB-INF
- |-->web.xml
-->We can take html file as error page but not recommend to take because we can't use the implicit object exception
-->While working with global error pages configurations we can configure different error pages for different exceptions
In web.xml
- <web-app>
- <error-page>
- <exception-type>java.lang.NumberFormatException</exception-type>
- <location>/err.jsp</locations>
- </error-page>
- <error-page>
- <exception-type>java.lang.NullPointerException</exception-type>
- <location>/myErr.html</locations>
- </error-page>
- </web-app>
Note: Jsp error pages configurations is no way related to servlet error pages
-->If we configure both local and global error pages on certain main jsp file , then the configurations done in local error page executes
(Q) What is the difference between the implicit object page & pageContext ?
In JES class
- final java.lang.Object page=this;
- pageContext=_jspxFactory.getPageContext(this,request,response,"err.jsp"(error.jsp),true(session mode),8192(buffer size),true(autoFlush mode));
page
-->Holds JES class object reference
-->Useful to differentiate scriptlet tags variables from declaration tag variable when both have got same name
pageContext
-->Holds details about current jsp page like request, response, error page, buffer size and etc...
-->Useful to create different scopea of attributes like request /session/ application and etc...
Comments
Post a Comment
Express your feelings