AddressBook/web/RequestDelete.jsp

Notes

Purpose
The purpose of RequestDelete.jsp is to produce a web page with a table showing the address that is to be deleted. The user may then either continue the delete process by selecting a link to DoDelete.jsp or abort the process by selecting a link back to Home.jsp. Figure 13 shows an example of the RequestDelete web page.

[Figure13]


Outer Shell
This html code outputs the shell of the page with a link to DoDelete.jsp labelled "Continue Delete Address Request nnn" and a link to Home.jsp labelled "Return to AddressBook Home Page [the address will not be deleted]", both at the bottom of the page:

    <html>
        <head>
            <title>AddressBook: Request Delete Address <%= request.getParameter ("id") %></title>
        </head>
        <body bgcolor="#ffffee">
            <h1><center>AddressBook: Request Delete Address <%= request.getParameter ("id") %></center></h1>

            ... code to retrieve address data to be deleted goes here ...

            <br>
            <center>
                <b><a href="DoDelete.jsp?id=<%= address.getId () %>">Continue Delete Address Request <%= request.getParameter ("id") %></a></b>
            </center>
            <hr>
            <center>
                <b><a href="Home.jsp">Return to AddressBook Home Page [the address will not be deleted]</a></b>
            </center>
        </body>
    </html>

When the "Continue Delete Address Request nnn" link is selected the id parameter is passed to DoDelete.jsp.


Retrieve Address Data to be Deleted
This java code retrieves the AddressBook.AddressesDB instance stored in the the web application's "addressesDB" attribute by AddressBook.ContextListener:

    AddressBook.AddressesDB addressesDB = (AddressBook.AddressesDB) application.getAttribute ("addressesDB");

Then it gets the address from the addresses database whose id has been passed as a parameter to this page by Home.jsp:

    AddressBook.Address address = (AddressBook.Address) addressesDB.getAddress (request.getParameter ("id"));
    if (address != null)
    {

        ... code to display the table goes here ...

    }
    else
    {
%>
        <center>
            <h2><font color="#cc0000">Could Not Find Address <%= request.getParameter ("id") %></font></h2>
        </center>
<%
    }


Display the Table
This html code with interspersed java code displays a table; the left column of the table displays the names of the address fields; the right column displays the address data:

    <table align="center" cellpadding="2" cellspacing="2" border="1" width="80%" bgcolor="#dddddd">
        <tr>
            <th>ID:</th>
            <td><%= address.getId () %></td>
        </tr>
        <tr>
            <th>Surname:</th>
            <td><%= address.getSurname () %></td>
        </tr>
        <tr>
            <th>Firstname:</th>
            <td><%= address.getFirstname () %></td>
        </tr>
        <tr>
            <th>Street:</th>
            <td><%= address.getStreet () %></td>
        </tr>
        <tr>
            <th>District:</th>
            <td><%= address.getDistrict () %></td>
        </tr>
        <tr>
            <th>City:</th>
            <td><%= address.getCity () %></td>
        </tr>
        <tr>
            <th>Postcode:</th>
            <td><%= address.getPostcode () %></td>
        </tr>
    </table>


Complete Source Code


<%@ page language="java" %>

<html>
    <head>
        <title>AddressBook: Request Delete Address <%= request.getParameter ("id") %></title>
    </head>
    <body bgcolor="#ffffee">
        <h1><center>AddressBook: Request Delete Address <%= request.getParameter ("id") %></center></h1>
<%
        AddressBook.AddressesDB addressesDB = (AddressBook.AddressesDB) application.getAttribute ("addressesDB");
        AddressBook.Address address = (AddressBook.Address) addressesDB.getAddress (request.getParameter ("id"));
        if (address != null)
        {
%>
            <table align="center" cellpadding="2" cellspacing="2" border="1" width="80%" bgcolor="#dddddd">
                <tr>
                    <th>ID:</th>
                    <td><%= address.getId () %></td>
                </tr>
                <tr>
                    <th>Surname:</th>
                    <td><%= address.getSurname () %></td>
                </tr>
                <tr>
                    <th>Firstname:</th>
                    <td><%= address.getFirstname () %></td>
                </tr>
                <tr>
                    <th>Street:</th>
                    <td><%= address.getStreet () %></td>
                </tr>
                <tr>
                    <th>District:</th>
                    <td><%= address.getDistrict () %></td>
                </tr>
                <tr>
                    <th>City:</th>
                    <td><%= address.getCity () %></td>
                </tr>
                <tr>
                    <th>Postcode:</th>
                    <td><%= address.getPostcode () %></td>
                </tr>
            </table>
            <br>
            <center>
                <b><a href="DoDelete.jsp?id=<%= address.getId () %>">Continue Delete Address Request <%= request.getParameter ("id") %></a></b>
            </center>
<%
        }
        else
        {
%>
            <center>
                <h2><font color="#cc0000">Could Not Find Address <%= request.getParameter ("id") %></font></h2>
            </center>
<%
        }
%>
        <hr>
        <center>
            <b><a href="Home.jsp">Return to AddressBook Home Page [the address will not be deleted]</a></b>
        </center>
    </body>
</html>