0% found this document useful (0 votes)
27 views12 pages

JSP Exception Handling

nice pdf

Uploaded by

ALL IN ONE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views12 pages

JSP Exception Handling

nice pdf

Uploaded by

ALL IN ONE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Department of CSE

ENTERPRISE PROGRAMMING
21CI2107
Topic:

JSP Exception Handling

Session - 1

CREATED BY K. VICTOR BABU


AIM OF THE SESSION

To familiarize students with the basic concept of

INSTRUCTIONAL OBJECTIVES

This Session is designed to:


1. Demonstrate
2. Describe
3. List out the
4. Describe the

LEARNING OUTCOMES

At the end of this session, you should be able to:


1. Define
2. Describe
3. Summarize

CREATED BY K. VICTOR BABU


SESSION INTRODUCTION

JSP Exception Handling

• Exception Handling is a process of handling exceptional condition that might occur


in your application.

• Exception Handling in JSP is much easier than Java Technology exception


handling.

• Although JSP Technology also uses the same exception class objects.

CREATED BY K. VICTOR BABU


SESSION INTRODUCTION

JSP provide 3 different ways to perform exception handling:

1. Using isErrorPage and errorPage attribute of page directive.

2. Using <error-page> tag in Deployment Descriptor.

3. Using simple try...catch block.

CREATED BY K. VICTOR BABU


SESSION DESCRIPTION
1.Example of isErrorPage and errorPage attribute
error.jsp

CREATED BY K. VICTOR BABU


SESSION DESCRIPTION (Cont..)

Basic Attributes of Action Tags


sum.jsp

CREATED BY K. VICTOR BABU


SESSION DESCRIPTION (Cont..)

2.Declaring error page in Deployment Descriptor


Declaring an error page for all type of exception
<error-page>
<exception-type>java.lang.Throwable</exceptiontype>
<location>/error.jsp</location>
</error-page>
Declaring an error page for more detailed exception
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/error.jsp</location>
</error-page>

Declaring an error page based on HTTP Status code


<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>

CREATED BY K. VICTOR BABU


SESSION DESCRIPTION (Cont..)
3.Using the try...catch block
Using try...catch block is just like how it is used in Core Java.
<html>
<head>
<title>Try...Catch Example</title>
</head>
<body> out.println("The answer is " + i);
<% }
Try catch (Exception e)
{ {
int i = 100; out.println("An exception occurred: " + e.getMessage());
i = i / 0; }
%>
</body>
</html>
CREATED BY K. VICTOR BABU
SELF-ASSESSMENT QUESTIONS

1. Which of the following attribute is used to have uncaught run-time exceptions automatically
forwarded to an error processing page?

(a) error
(b) Error page

(c) exception
(d) Exception page

2. Which of the following exceptions are


thrown by the JVM?

A. ArrayIndexOutOfBoundsException
B. ExceptionInInitializerError
C. java.io.IOException
D. NullPointerException
E. NumberFormatException

CREATED BY K. VICTOR BABU


TERMINAL QUESTIONS

1. Describe

2. List out

3. Analyze

4. Summarize

CREATED BY K. VICTOR BABU


REFERENCES FOR FURTHER LEARNING OF THE SESSION

Reference Books:
1. JSP and Java servlet programming
2. The complete Reference JSP, Phil Hanna.
3. JSP And Servlets: A Comprehensive Study, Mahesh P. Matha

Sites and Web links:


1. https://www.tutorialspoint.com/jsp/jsp_questions_answers.htm
2. https://www.sanfoundry.com/advanced-java-questions-answers-jsp/
3. https://www.javaguides.net/2020/12/java-exception-handling-quiz-multiple-choice-questions.html

CREATED BY K. VICTOR BABU


THANK YOU

Team – Course Name

CREATED BY K. VICTOR BABU

You might also like