Class 2 Intermediate Java 30-IT-397  

Exceptions Example

<%@page contentType="text/html"%>
<html>
<head><title>Simple Calculator</title></head>
<body>
<%--
Numbers.jsp

An example to demonstrate exception handling.
If the input data are not well formed or do not exist, error.jsp will catch the exception.

Brandan Jones
University of Cincinnati
jonesbr@email.uc.edu
December 26, 2001
--%>

<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName"  property="propertyName" /> --%>
<%@ page errorPage="error.jsp" %>
 

If entered correctly, you will see the total of the two numbers you sent me.
<%
String strFirstNumber = request.getParameter("firstNumber");
String strSecondNumber = request.getParameter("secondNumber");
int total = Integer.parseInt(strFirstNumber) + Integer.parseInt(strSecondNumber);
out.print("<h2>The total of the numbers is: " + total);
%>
 

</body>
</html>
 

<%@page contentType="text/html"%>
<html>
<head><title>JSP Page</title></head>
<body>

<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName"  property="propertyName" /> --%>

<%@ page isErrorPage="true" %>
Exception caught while attempting to hanlde your request: <%= exception %>.
<br>Stack Trace:
<br><% exception.printStackTrace(new PrintWriter(out)); %>

</body>
</html>

 The Results
 

Created by:  Brandan Jones December 20, 2001