Purpose
The purpose of RequestAdd.jsp is to produce a web page with a form that the user fills with address data. The user may then either submit the form's data for processing by transferring control to DoAdd.jsp or abort the process by selecting a link back to Home.jsp. Figure 11 shows an example of the RequestAdd web page.
![[Figure11]](/onjava/2003/01/08/graphics/figure11.jpg)
Outer Shell
This html code outputs the shell of the page with a link to Home.jsp labelled "Return to AddressBook Home Page [the address will not be added]" at the bottom of the page:
<html>
<head>
<title>AddressBook: Request Add a New Address</title>
</head>
<body bgcolor="#ffffee">
<h1><center>AddressBook: Request Add a New Address</center></h1>
... code to display the form goes here ...
<hr>
<center>
<b><a href="Home.jsp">Return to AddressBook Home Page [the address will not be added]</a></b>
</center>
</body>
</html>
Display the Form
This html code with interspersed java code creates a form whose action to post the address data in the input fields to DoAdd.jsp:
<form method="post" action="DoAdd.jsp">
Then a table is displayed; the left column of the table displays the names of the address fields; the right column contains the input fields:
<table align="center" cellpadding="2" cellspacing="2" border="1" width="80%" bgcolor="#dddddd">
<tr>
<th>Surname:</th>
<td><input name="surname" type="text"></td>
</tr>
<tr>
<th>Firstname:</th>
<td><input name="firstname" type="text"></td>
</tr>
<tr>
<th>Street:</th>
<td><input name="street" type="text"></td>
</tr>
<tr>
<th>District:</th>
<td><input name="district" type="text"></td>
</tr>
<tr>
<th>City:</th>
<td><input name="city" type="text"></td>
</tr>
<tr>
<th>Postcode:</th>
<td><input name="postcode" type="text"></td>
</tr>
</table>
Then a hidden field that will simulate the pressing of the submit button when the return key is pressed is defined:
<input name="pagemode" type="hidden" value="submit">
Then the form submit button labelled "Continue Add Address Request" is displayed:
<input type="submit" value="Continue Add Address Request">
When the submit button is pressed the surname, firstname, street, district, city, and postcode parameters are passed to DoAdd.jsp.
<%@ page language="java" %>
<html>
<head>
<title>AddressBook: Request Add a New Address</title>
</head>
<body bgcolor="#ffffee">
<h1><center>AddressBook: Request Add a New Address</center></h1>
<form method="post" action="DoAdd.jsp">
<table align="center" cellpadding="2" cellspacing="2" border="1" width="80%" bgcolor="#dddddd">
<tr>
<th>Surname:</th>
<td><input name="surname" type="text"></td>
</tr>
<tr>
<th>Firstname:</th>
<td><input name="firstname" type="text"></td>
</tr>
<tr>
<th>Street:</th>
<td><input name="street" type="text"></td>
</tr>
<tr>
<th>District:</th>
<td><input name="district" type="text"></td>
</tr>
<tr>
<th>City:</th>
<td><input name="city" type="text"></td>
</tr>
<tr>
<th>Postcode:</th>
<td><input name="postcode" type="text"></td>
</tr>
</table>
<br>
<center>
<input name="pagemode" type="hidden" value="submit">
<input type="submit" value="Continue Add Address Request">
</center>
<hr>
<center>
<b><a href="Home.jsp">Return to AddressBook Home Page [the address will not be added]</a></b>
</center>
</body>
</html>
|