Home Jsp How to create and use custom error page in jsp

Related Tutorials


 
 

Share on Google+Share on Google+

How to create and use custom error page in jsp

Advertisement
This is detailed java code how to create and use custom error page in jsp and display an error message.

How to create and use custom error page in jsp

     

This is detailed java code how to create and use custom error page in jsp and display an error message.

Before run this java code create a new directory named "user" in the tomcat-6.0.16/webapps and paste WEB-INF directory in same directory.

 

 

 

 

 

error_page.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page isErrorPage = "true"%>
<%@ page import = "java.io.*" %>
<HTML>
    <HEAD>
        <TITLE> custom error page </TITLE>
    </head>
    <body>
       <h2>Your application has generated an error</h2>
       <h3>Please check for the error given below</h3>
       <b>Exception:</b><br> 
       <font color="red"><%= exception.toString() %></font>
    </body>
</html>

Save this code as a .jsp file named "error_page.jsp" in the directory Tomcat-6.0.16/webapps/user/ 

calculation_page.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%-- include custom error page in this jsp code --%>
<%@ page errorPage="error_page.jsp" %>
<html>
    <head>
        <title>calculation page</title>
    </head>
    <body>
       <% 
	     int i = 10;
	     // This line will create an error so 
             error page will be called
             i = i / 0;
       %>
    </body>
</html>

Save this code as a .jsp file named "calculation_page.jsp" in the directory Tomcat-6.0.16/webapps/user/ and run this page with the following url in address bas in browser http://localhost:8080/user/calculation_page.jsp

When run this jsp page in browser, mathematical calculation (devide by 0) will generate an error so the error page will be called on that time and result will be the custom error page.

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: July 8, 2008

Related Tutorials

Discuss: How to create and use custom error page in jsp   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
vasu
April 17, 2014
error messages display

how can i display error message or success message in when i want in front view it means above table .i am using out.println and also request dispatcher these two are displaying in some where in page
DMCA.com