Source - calculatorErrors.jsp
<%-- ------------------------------------------------------------------
Declare this page as an error page.
------------------------------------------------------------------ --%>
<%@ page language="java" isErrorPage="true" %>
<%-- -------------------------------------------------------------
We will use the <c:out> tag from the Java Standard Tag Library
(JSTL)to retrieve and display the request parameters and messages
from the error object. There are currently four libraries of
standard actions: core, XML processing, formatting, and SQL.
We only need the core tags for this application.
uri an absolute URI that identifies the tag library.
prefix a short XML namespace identifier used as a prefix to
all tags from this library. For example: <c:out />
------------------------------------------------------------- --%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%-- -----------------------------------------------------
Write the HTML to draw the calculator form and display
the errors. We will use the <c:out> tag to display the
raw parameter value strings from the request rather than
retrieve them from the bean so the viewer can see their
original entries. We will also display an error message
above each field that has an entry in the error object.
------------------------------------------------------ --%>
<html>
<head>
<title>Financial Calculator Errors</title>
<link rel="stylesheet" href="standard.css">
</head>
<body>
<div align="center">
<%-- -------------------------------------------------------
Display the HTML form. Notice that the action attribute
will cause the request to be posted to the servlet controller
(calculator) when the submit button is clicked. The servlet
will then edit each form field, set the values into the TVM
bean, and ask the bean to calculate the result. If all goes
well, the servlet will then forward the request to the
<a href="claculatorform.html">calculator form</a>for display. If there are errors, the request
will be forwarded back to this error page for display
instead. This cycle will repeat until the viewer leaves the
application.
------------------------------------------------------ --%>
<form method="post" action="calculator">
<table border="0" cellpadding="10" cellspacing="0">
<tr>
<td align="center" colspan="2"><h2>Financial Calculator</h2></td>
</tr>
<%-- -------------------------------------------------------
Display Present Value.
The error object contains errors that the controller found.
The param object contains the original form entries.
------------------------------------------------------ --%>
<tr>
<td colspan="2" class="error"><c:out value='${errors.pv}' /></td>
</tr>
<tr>
<td align="right">Present Value:</td>
<td align="left"> <input
name="presentValue"
type="text" size="20"
value='<c:out value="${param.presentValue}" />'
</td>
</tr>
<%-- -------------------------------------------------------
Display Future Value.
------------------------------------------------------ --%>
<tr>
<td colspan="2" class="error"><c:out value="${errors.fv}" /></td>
</tr>
<td align="right">Future Value:</td>
<td><input
name="futureValue"
type="text" size="20"
value='<c:out value="${param.futureValue}" />' >
</td>
</tr>
<%-- -------------------------------------------------------
Display Payment.
------------------------------------------------------ --%>
<tr>
<td colspan="2" class="error"><c:out value="${errors.pmt}" /></td>
</tr>
<td align="right">Payment:</td>
<td><input
name="payment"
type="text" size="20"
value='<c:out value="${param.payment}" />' >
</td>
</tr>
<%-- -------------------------------------------------------
Display Interest Rate.
------------------------------------------------------ --%>
<tr>
<td colspan="2" class="error"><c:out value="${errors.i}" /></td>
</tr>
<td align="right">Interest Rate:</td>
<td align="left"><input
name="interestRate"
type="text" size="5"
value='<c:out value="${param.interestRate}" />' >
</td>
</tr>
<%-- -------------------------------------------------------
Display Number Of Periods.
------------------------------------------------------ --%>
<tr>
<td colspan="2" class="error"><c:out value="${errors.n}" /></td>
</tr>
<td align="right">Periods:</td>
<td align="left"><input
name="numberOfPeriods"
type="text" size="5"
value='<c:out value="${param.numberOfPeriods}" />' >
</td>
</tr>
<tr>
<td colspan="2"><hr></td>
</tr>
<%-- -------------------------------------------------------
Display the form's Submit (calculate) button and a Select
drop-down component that allows the viewer to choose which
of the five fields to compute.
------------------------------------------------------ --%>
<tr>
<td colspan="2" class="error"><c:out value="${errors.cmp}" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Calculate">
<select name="op" size="1">
<option SELECTED>Payment
<option>Present Value
<option>Future Value
<option>Interest Rate
<option>Periods
</select>
<br>
</td>
</tr>
</table>
<form>
</div>
</body>
</html>
|