Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp JSP Error Page

Related Tutorials


 
 

Share on Google+Share on Google+

JSP Error Page

Advertisement
This page discusses - JSP Error Page

JSP Error Page

        

JSP Error Page is used to specify the custom error page and runtime error occurs with an exception being thrown, the custom error page helps in handling the error page and display a customized view of the exception.

Understand with Example

In this section, you will learn the use of errorPage attribute of the page directive in jsp. This attribute sets a url and if any exception is generated it refers to the file which is mentioned in the given url. If you do not specify the url then the attribute refers to the current page of your JSP application. Here we have used two jsp pages:
1) error.jsp
2) errorPage.jsp

In the error.jsp page, we have initialized a string variable to null in a scriplet and use the method st.length() inorder to determine the length of the string which is the  cause of generating an error. This page is redirected to the errorPage.jsp as specified in the errorPage attribute of the page directive. The page errorPage.jsp shows the error generated in calling the JSP page by setting the isErrorPage attribute to true.

Here is the code of error.jsp

<%@page errorPage="errorPage.jsp" %>
<html>
<head><title>Error Page</title></head>
<body>
<%! 
String st = null;
%>
The length of the string is <%= st.length() %>
</body>
</html>

Here is the code of errorPage.jsp

<%@ page isErrorPage="true" import="java.io.*" %>
<html>
<body>
<h2>Error Encountered!</h2>
<font color="red"><%= exception %> has been encountered. You haven't specify any String.</font>
</body>
</html>

Output will be displayed as:

Download Source Code:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: JSP Error Page  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com