This is an example project that can be an aide or alternative to your own class project. Based on your time availability use it to guide you as you build you own project or make a version of it as your own class project. Please only share this information with other enrolled class members.

Simple Address Book Version 2.0w

Simple Address Book implemented using a multi-layer architecture and interfaces to use each layer.
This version of the project has about 6 weeks of part-time effort to give you a great start/guide on your projects.

Contacts are stored in two separate tables for the person information and the address information. The records are related by the person’s id field using the ContactService business logic (not the database). Each person can have only one address.
This application allows you to save, get, delete, or list contacts.

1) Project

Project Name: SimpleAddressBook-2.0w
This is an Eclipse Java Dynamic Web Project.

2) High Level Requirements

Click here to open the high level requirements in a separate tab/window. Return here when finish by finding the tab in your browser.

3) Packages, Interfaces, and Classes

Simple Address Book v2.0w

Simple Address Book v2.0w


Click here to open the high level Packages, Interfaces, and Classes from weeks 2-4 in a separate tab/window. Return here when finish by finding the tab in your browser.


4) Web Application Activity Diagram

Design-SimpleAddressBookV2-0w-OzBrown

5) Design Details, Packages, Interfaces, and Classes

6) Prototype Web Page

SimpleAB 2.0w Prototype index

SimpleAB 2.0w Prototype index

...
<tr>
<td>15</td>
<td>Tom</td>
<td>Smith</td>
<td>any@email.com</td>
<td>Plano, TX</td>
<td><button onclick="location.href='view.html';">View</button><button onclick="location.href='edit.html';">Edit</button><button onclick="location.href='delete.html';">Delete</button></td>
</tr>
<tr>
<td>16</td>
<td>Judy</td>
<td>Jones</td>
<td>another@email.com</td>
<td>Frisco, TX</td>
<td><button onclick="location.href='view.html';">View</button><button onclick="location.href='edit.html';">Edit</button><button onclick="location.href='delete.html';">Delete</button></td>
</tr>
...

SimpleAB 2.0w Prototype view

SimpleAB 2.0w Prototype view

...
<div class="bottomnav"><button onclick="location.href='list';">Cancel</button></div>
<form method="get" action="edit.html">
<div class="bottomnav"><input type="submit" value="Edit" /></div>
</form>
<form method="get" action="delete.html">
<div class="bottomnav"><input type="submit" value="Delete" /></div>
</form>
...

SimpleAB 2.0w Prototype edit

SimpleAB 2.0w Prototype edit

...
<form action="#">
<div class="viewlabel">id</div><div class="viewvalue"><input type="text" value="16" /></div>
<div class="viewlabel">First Name</div><div class="viewvalue"><input type="text" value="Judy" /></div>
<div class="viewlabel">Last Name</div><div class="viewvalue"><input type="text" value="Jones" /></div>
<div class="viewlabel">Gender</div><div class="viewvalue"><input type="text" value="Female" /></div>
<div class="viewlabel">D.O.B.</div><div class="viewvalue"><input type="text" value="03-25-1968" /></div>
<div class="viewlabel">Email</div><div class="viewvalue"><input type="text" value="another@email.com" /></div>
<div class="viewlabel">Street</div><div class="viewvalue"><input type="text" value="456 Avenue" /></div>
<div class="viewlabel">City</div><div class="viewvalue"><input type="text" value="Frisco" /></div>
<div class="viewlabel">State</div><div class="viewvalue"><input type="text" value="TX" /></div>
<div class="viewlabel">ZipCode</div><div class="viewvalue"><input type="text" value="75034" /></div>
</form>
<div style="clear: both;">&nbsp;</div>
<div class="bottomnav"><button onclick="location.href='index.html';">Cancel</button></div>
<form method="post" action="edit.html">
<div class="bottomnav"><input type="submit" value="Save" /></div>
</form>
<div class="bottomnav"><button onclick="location.href='delete.html';">Delete</button></div>
...

SimpleAB 2.0w Prototype save

SimpleAB 2.0w Prototype save


Generated from Servlet


SimpleAB 2.0w Prototype delete

SimpleAB 2.0w Prototype delete

...
<div class="bottomnav"><button onclick="location.href='index.html';">Cancel</button></div>
<div class="bottomnav">&nbsp;</div>
<form method="post" action="delete.html">
<div class="bottomnav"><input type="submit" value="Confirm Delete" /></div>
</form>
...

SimpleAB 2.0w Prototype confirm delete

SimpleAB 2.0w Prototype confirm delete


Generated from Servlet


7) Coding

ListContactServlet.java

package com.ogbrown.simpleab.servlet;
 
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * Servlet implementation class HelloWorldServlet
 */
public class ListContactServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListContactServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        String url = "/WEB-INF/listContacts.html";
        getServletContext().getRequestDispatcher(url).
           forward(request, response);
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
 
}

ViewContactServlet.java

package com.ogbrown.simpleab.servlet;
 
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * Servlet implementation class HelloWorldServlet
 */
public class ViewContactServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ViewContactServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        String url = "/WEB-INF/viewContact.html";
        getServletContext().getRequestDispatcher(url).
           forward(request, response);
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
    	String url = "/edit.html";

        response.sendRedirect(url);
    }
 
}

UpdateContactServlet.java

package com.ogbrown.simpleab.servlet;

import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloWorldServlet
 */
public class UpdateContactServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public UpdateContactServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String url = "/WEB-INF/editContact.html";
		getServletContext().getRequestDispatcher(url).forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<head>");
		out.println("    <meta http-equiv=\"refresh\" content=\"5;url=index.html\" />");
		out.println("</head>");
		out.println("<body>");
		out.println("    <h2>Updating Judy Jones<br />... returning to list in 5 seconds...</h2>");
		out.println("    <h3 style=\"color:red\">Ok... not really updating... prototype</h3>");
		out.println("    </body>");
		out.println("</html>");
	}

}

DeleteContactServlet.java

package com.ogbrown.simpleab.servlet;
 
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * Servlet implementation class HelloWorldServlet
 */
public class DeleteContactServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteContactServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        String url = "/WEB-INF/deleteContact.html";
        getServletContext().getRequestDispatcher(url).
           forward(request, response);
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
    	PrintWriter out = response.getWriter();
    	out.println("<html>");
    	out.println("<head>");
    	out.println("    <meta http-equiv=\"refresh\" content=\"5;url=index.html\" />");
    	out.println("</head>");
    	out.println("<body>");
    	out.println("    <h1>Deleting Judy Jones... returning to list in 5 seconds...</h1>");
    	out.println("    <h3 style=\"color:red\">Ok... not really deleting... prototype</h3>");
    	out.println("</body>");
    	out.println("</html>");
    }
 
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	version="3.0">
	<display-name>SimpleAddressBook</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>

	<servlet>
		<servlet-name>ListServlet</servlet-name>
		<servlet-class>com.ogbrown.simpleab.servlet.ListContactServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>ListServlet</servlet-name>
		<url-pattern>/index.html</url-pattern>
		<url-pattern>/list</url-pattern>
	</servlet-mapping>

	<servlet>
		<servlet-name>ViewServlet</servlet-name>
		<servlet-class>com.ogbrown.simpleab.servlet.ViewContactServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>ViewServlet</servlet-name>
		<url-pattern>/view.html</url-pattern>
		<url-pattern>/view</url-pattern>
	</servlet-mapping>

	<servlet>
		<servlet-name>UpdateServlet</servlet-name>
		<servlet-class>com.ogbrown.simpleab.servlet.UpdateContactServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>UpdateServlet</servlet-name>
		<url-pattern>/edit.html</url-pattern>
		<url-pattern>/edit</url-pattern>
	</servlet-mapping>

	<servlet>
		<servlet-name>DeleteServlet</servlet-name>
		<servlet-class>com.ogbrown.simpleab.servlet.DeleteContactServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>DeleteServlet</servlet-name>
		<url-pattern>/delete.html</url-pattern>
		<url-pattern>/delete</url-pattern>
	</servlet-mapping>
</web-app>