Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
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.

 

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

                         

» View all related tutorials
Related Tags: c exception error jsp io count page using invoke js handle if to ci counter e directive can pe ce

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.