SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Chapter 3



Error Handling



                 http://www.java2all.com
Introduction



               http://www.java2all.com
We already know about error and exception.

   In JSP there are 2 types of exception
1.      Translation time errors
2.      Run Time Exception
       Translation error occurs during page
   compilation, this results in an Internal Server Error
   (500).
       An exception on other hand occurs when page is
   compiled and servlet is running.
       Exception can be handled in JSP in three ways:

                                             http://www.java2all.com
a.) Java Exception Handling mechanism

b.) Dealing with exception with page directive

c.) Dealing with exception in Deployment
    Descriptor.




                                     http://www.java2all.com
By Mechanism




               http://www.java2all.com
Java Exception handling mechanism

InputData.html :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>InputData.html</title>
 </head>
 <body>
  <form action="../JSPFILE/Calculator.jsp">
  <input type="text" name="n1"> <br>
  <input type="text" name="n2"> <br>
  <input type="submit" value="ADD">
  </form>
 </body>
</html>




                                                                  http://www.java2all.com
Calculator.jsp :
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<html>
 <head>
 <title> Calculator.jsp </title>
 </head>
 <body>
 <% try
   {
     int i1 = Integer.parseInt(request.getParameter("n1"));
     int i2 = Integer.parseInt(request.getParameter("n2"));
     int add = i1 + i2;
     out.print("Addition = "+add);
   }
   catch(NumberFormatException ne)
   {
     out.print("Esception : "+ne);
   }
 %>

 </body>
</html>


                                                                            http://www.java2all.com
URL :
http://localhost:8080/JAVA_PROJECT/HTMLFILE/Input
Data.html




                                        http://www.java2all.com
                                        http://www.java2all.com
Input the integer value in text fields and click
ADD button.

     The browser display the below message,
     Addition = 11

     Now, input the float value in any of the text field
and click ADD button so the browser display the
message,

     Exception :
     java.lang.NumberFormatException: For
input string: "6.3"
                                              http://www.java2all.com
http://www.java2all.com
 http://www.java2all.com
By Page Directive




                    http://www.java2all.com
Dealing exception with page directive :

      The two attributes of page directive
errorPage and isErrorPage are used to deal with
exception.
InputData.html :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>InputData.html</title>
 </head>
 <body>
  <form action="../JSPFILE/Calculator.jsp">
  <input type="text" name="n1"> <br>
  <input type="text" name="n2"> <br>
  <input type="submit" value="ADD">
  </form>
 </body>
</html>
                                                                  http://www.java2all.com
Calculator.jsp :
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"
errorPage="Error.jsp"%>

<html>
 <head>
 <title> Calculator.jsp </title>
 </head>

 <body>
 <%
    int i1 = Integer.parseInt(request.getParameter("n1"));
    int i2 = Integer.parseInt(request.getParameter("n2"));
    int add = i1 + i2;
    out.print("Addition = "+add);

 %>

 </body>
</html>




                                                                          http://www.java2all.com
Error.jsp :
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"
isErrorPage="true"%>
<html>
  <head>
  <title>Error.jsp</title>
  </head>
  <body>
  Your page generate an Exception. <br>
  <%= exception.getMessage() %>
  </body>
</html>




                                                                          http://www.java2all.com
Input the integer value in textfields and click
ADD button.

     The browser display the below message,
     Addition = 11

      Now, input the float value in any of the
textfield and click ADD button so the browser
display the message,

     Your page generate an Exception.
     For input string: "6.3"
                                            http://www.java2all.com
In Deployment Descriptor




                      http://www.java2all.com
InputData.html :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>InputData.html</title>
 </head>
 <body>
  <form action="../JSPFILE/Calculator.jsp">
  <input type="text" name="n1"> <br>
  <input type="text" name="n2"> <br>
  <input type="submit" value="ADD">
  </form>
 </body>
</html>




                                                                  http://www.java2all.com
Calculator.jsp :
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<html>
 <head>
 <title> Calculator.jsp </title>
 </head>

 <body>
 <%
    int i1 = Integer.parseInt(request.getParameter("n1"));
    int i2 = Integer.parseInt(request.getParameter("n2"));
    int add = i1 + i2;
    out.print("Addition = "+add);

 %>

 </body>
</html>




                                                                            http://www.java2all.com
Error.jsp :
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"
isErrorPage="true"%>
<html>
  <head>
  <title>Error.jsp</title>
  </head>
  <body>
  Your page generate an Exception. <br>
  <%= exception.getMessage() %>
  </body>
</html>




                                                                          http://www.java2all.com
Web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>

 <error-page>
  <exception-
type>java.lang.NumberFormatException</exce
ption-type>
  <location>/Error.jsp</location>
 </error-page>
</web-app>
                                                          http://www.java2all.com
NOTE : web.xml (deployment descriptor) file is
available in WEB-INF folder at WebRoot.

   Input the integer value in textfields and click
ADD button.

     The browser display the below message,
     Addition = 11

      Now, input the float value in any of the
textfield and click ADD button so the browser
display the message,
                                            http://www.java2all.com
Your page generates an Exception.
     For input string: "6.3“

     This deployment descriptor entry means that
whenever a web component throws a
NumberFormatException from any web page in
the whole application(web project),

     the web container call the Error.jsp file,
which simply reports the error message in web
browser.

                                             http://www.java2all.com

Weitere ähnliche Inhalte

Was ist angesagt?

Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to JavascriptAnjan Banda
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...Edureka!
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in javaJayasankarPR2
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 
JavaScript Fetch API
JavaScript Fetch APIJavaScript Fetch API
JavaScript Fetch APIXcat Liu
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+featuresFaisal Aziz
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptMuhammadRehan856177
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 

Was ist angesagt? (20)

Callback Function
Callback FunctionCallback Function
Callback Function
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Javascript
JavascriptJavascript
Javascript
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
JavaScript Fetch API
JavaScript Fetch APIJavaScript Fetch API
JavaScript Fetch API
 
Lesson 5 php operators
Lesson 5   php operatorsLesson 5   php operators
Lesson 5 php operators
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
Angular overview
Angular overviewAngular overview
Angular overview
 
sets and maps
 sets and maps sets and maps
sets and maps
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).ppt
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 

Ähnlich wie JSP Error handling

Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -ServletsGagandeep Singh
 
Oracle Endeca Developer's Guide
Oracle Endeca Developer's GuideOracle Endeca Developer's Guide
Oracle Endeca Developer's GuideKeyur Shah
 
การเข ยนโปรแกรมต ดต_อฐานข_อม_ล
การเข ยนโปรแกรมต ดต_อฐานข_อม_ลการเข ยนโปรแกรมต ดต_อฐานข_อม_ล
การเข ยนโปรแกรมต ดต_อฐานข_อม_ลBongza Naruk
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran TochAdil Jafri
 
Servlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtpServlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtpodilodif
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceNiraj Bharambe
 
Build Your First Java Jersey JAX-RS REST Web Service in less than 15 Minutes
Build Your First Java Jersey JAX-RS REST Web Service in less than 15 MinutesBuild Your First Java Jersey JAX-RS REST Web Service in less than 15 Minutes
Build Your First Java Jersey JAX-RS REST Web Service in less than 15 MinutesRobert Li
 
jQuery basics
jQuery basicsjQuery basics
jQuery basicsKamal S
 
DRYing Up Rails Views and Controllers
DRYing Up Rails Views and ControllersDRYing Up Rails Views and Controllers
DRYing Up Rails Views and ControllersJames Gray
 
Java serverpages
Java serverpagesJava serverpages
Java serverpagesAmit Kumar
 

Ähnlich wie JSP Error handling (20)

Jsp element
Jsp elementJsp element
Jsp element
 
Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -Servlets
 
Oracle Endeca Developer's Guide
Oracle Endeca Developer's GuideOracle Endeca Developer's Guide
Oracle Endeca Developer's Guide
 
การเข ยนโปรแกรมต ดต_อฐานข_อม_ล
การเข ยนโปรแกรมต ดต_อฐานข_อม_ลการเข ยนโปรแกรมต ดต_อฐานข_อม_ล
การเข ยนโปรแกรมต ดต_อฐานข_อม_ล
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
 
Servlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtpServlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtp
 
Jsp intro
Jsp introJsp intro
Jsp intro
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer science
 
Rest hello world_tutorial
Rest hello world_tutorialRest hello world_tutorial
Rest hello world_tutorial
 
Jsp1
Jsp1Jsp1
Jsp1
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Build Your First Java Jersey JAX-RS REST Web Service in less than 15 Minutes
Build Your First Java Jersey JAX-RS REST Web Service in less than 15 MinutesBuild Your First Java Jersey JAX-RS REST Web Service in less than 15 Minutes
Build Your First Java Jersey JAX-RS REST Web Service in less than 15 Minutes
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
Test2
Test2Test2
Test2
 
Test2
Test2Test2
Test2
 
Lecture2
Lecture2Lecture2
Lecture2
 
DRYing Up Rails Views and Controllers
DRYing Up Rails Views and ControllersDRYing Up Rails Views and Controllers
DRYing Up Rails Views and Controllers
 
Ajax3
Ajax3Ajax3
Ajax3
 
Java serverpages
Java serverpagesJava serverpages
Java serverpages
 
Jsp tutorial
Jsp tutorialJsp tutorial
Jsp tutorial
 

Mehr von kamal kotecha

Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Examplekamal kotecha
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal kotecha
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with codekamal kotecha
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySqlkamal kotecha
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of javakamal kotecha
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7kamal kotecha
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 

Mehr von kamal kotecha (20)

Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Java rmi
Java rmiJava rmi
Java rmi
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 
Interface
InterfaceInterface
Interface
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
 
Class method
Class methodClass method
Class method
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Control statements
Control statementsControl statements
Control statements
 
Jsp myeclipse
Jsp myeclipseJsp myeclipse
Jsp myeclipse
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 

Kürzlich hochgeladen

week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 

Kürzlich hochgeladen (20)

week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 

JSP Error handling

  • 1. Chapter 3 Error Handling http://www.java2all.com
  • 2. Introduction http://www.java2all.com
  • 3. We already know about error and exception. In JSP there are 2 types of exception 1. Translation time errors 2. Run Time Exception Translation error occurs during page compilation, this results in an Internal Server Error (500). An exception on other hand occurs when page is compiled and servlet is running. Exception can be handled in JSP in three ways: http://www.java2all.com
  • 4. a.) Java Exception Handling mechanism b.) Dealing with exception with page directive c.) Dealing with exception in Deployment Descriptor. http://www.java2all.com
  • 5. By Mechanism http://www.java2all.com
  • 6. Java Exception handling mechanism InputData.html : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>InputData.html</title> </head> <body> <form action="../JSPFILE/Calculator.jsp"> <input type="text" name="n1"> <br> <input type="text" name="n2"> <br> <input type="submit" value="ADD"> </form> </body> </html> http://www.java2all.com
  • 7. Calculator.jsp : <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <html> <head> <title> Calculator.jsp </title> </head> <body> <% try { int i1 = Integer.parseInt(request.getParameter("n1")); int i2 = Integer.parseInt(request.getParameter("n2")); int add = i1 + i2; out.print("Addition = "+add); } catch(NumberFormatException ne) { out.print("Esception : "+ne); } %> </body> </html> http://www.java2all.com
  • 8. URL : http://localhost:8080/JAVA_PROJECT/HTMLFILE/Input Data.html http://www.java2all.com http://www.java2all.com
  • 9. Input the integer value in text fields and click ADD button. The browser display the below message, Addition = 11 Now, input the float value in any of the text field and click ADD button so the browser display the message, Exception : java.lang.NumberFormatException: For input string: "6.3" http://www.java2all.com
  • 11. By Page Directive http://www.java2all.com
  • 12. Dealing exception with page directive : The two attributes of page directive errorPage and isErrorPage are used to deal with exception. InputData.html : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>InputData.html</title> </head> <body> <form action="../JSPFILE/Calculator.jsp"> <input type="text" name="n1"> <br> <input type="text" name="n2"> <br> <input type="submit" value="ADD"> </form> </body> </html> http://www.java2all.com
  • 13. Calculator.jsp : <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1" errorPage="Error.jsp"%> <html> <head> <title> Calculator.jsp </title> </head> <body> <% int i1 = Integer.parseInt(request.getParameter("n1")); int i2 = Integer.parseInt(request.getParameter("n2")); int add = i1 + i2; out.print("Addition = "+add); %> </body> </html> http://www.java2all.com
  • 14. Error.jsp : <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1" isErrorPage="true"%> <html> <head> <title>Error.jsp</title> </head> <body> Your page generate an Exception. <br> <%= exception.getMessage() %> </body> </html> http://www.java2all.com
  • 15. Input the integer value in textfields and click ADD button. The browser display the below message, Addition = 11 Now, input the float value in any of the textfield and click ADD button so the browser display the message, Your page generate an Exception. For input string: "6.3" http://www.java2all.com
  • 16. In Deployment Descriptor http://www.java2all.com
  • 17. InputData.html : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>InputData.html</title> </head> <body> <form action="../JSPFILE/Calculator.jsp"> <input type="text" name="n1"> <br> <input type="text" name="n2"> <br> <input type="submit" value="ADD"> </form> </body> </html> http://www.java2all.com
  • 18. Calculator.jsp : <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <html> <head> <title> Calculator.jsp </title> </head> <body> <% int i1 = Integer.parseInt(request.getParameter("n1")); int i2 = Integer.parseInt(request.getParameter("n2")); int add = i1 + i2; out.print("Addition = "+add); %> </body> </html> http://www.java2all.com
  • 19. Error.jsp : <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1" isErrorPage="true"%> <html> <head> <title>Error.jsp</title> </head> <body> Your page generate an Exception. <br> <%= exception.getMessage() %> </body> </html> http://www.java2all.com
  • 20. Web.xml : <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <error-page> <exception- type>java.lang.NumberFormatException</exce ption-type> <location>/Error.jsp</location> </error-page> </web-app> http://www.java2all.com
  • 21. NOTE : web.xml (deployment descriptor) file is available in WEB-INF folder at WebRoot. Input the integer value in textfields and click ADD button. The browser display the below message, Addition = 11 Now, input the float value in any of the textfield and click ADD button so the browser display the message, http://www.java2all.com
  • 22. Your page generates an Exception. For input string: "6.3“ This deployment descriptor entry means that whenever a web component throws a NumberFormatException from any web page in the whole application(web project), the web container call the Error.jsp file, which simply reports the error message in web browser. http://www.java2all.com