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
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
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
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
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