CSE-2041A
Net-Centric Computing

York University
Fall 2011
Lab #4: Webapp
Contacts Phone Book
  Introduction

Welcome to lab #4. Let's build a webapp! Call it pb (phonebook).

 
  Contacts Phonebook
Requirements Document

The user starts by visiting the URL

https://www.cse.yorku.ca/~cseXXXXX/pb/pb.cgi

where cseXXXXX is your Red login. At that point, the browser prompts for username and password. Any valid Red user should be able to login. After a successful authentication, the user is presented with the a search page having the following components.

  1. A message that says “Welcome X”, where X is the user's username. If the user has visited the webapp before, then the message should say, “ Welcome back X. Your last visit was xxx.” The xxx should be the time of the person's last visit.

  2. A label, a textbox, and a button entitled “Find”. The user can enter a person's last name — or a part thereof — and click “Find” in order to initiate a database search for the telephone number of that person. The search should be case insensitive.

When the “Find” button is clicked, the entry is looked up in the database. If not found, the search page is re-served with an error message at the top that says “No match!”, and with the textbox pre-filled with whatever the user had entered.

If, however, the search was successful, the user is presented with a detail page which is made up of four label-textbox pairs:

  • Last Name

  • First Name

  • Telephone

  • Comments

The textboxes are to be pre-populated with values from the corresponding columns of the matching row in the database. (If several matches were found, then only the first one — in last name order — should be shown.)

Note that the textboxes must be in read-only mode, and that the 4{\em the} one must actually be a text area, in order to accommodate large comments. This page must also include a “Back” button to enable the user to return to the search page with its textbox pre-filled.

The Database

Create a table named Contact. Use the Derby database system from Lab #2 with the CSE “database”, using your Derby user name and password from Lab #2.

The file create_contact.sql describes the schema for the table. Use ij and that file to make your table:

run 'create_contact.sql';

Note that you do not set schema ... This table belongs to you, and so is under your default schema.

We will use just a subset of the columns today. Use phone1 to hold the telephone number. Note that the ID column is an integer that is auto-generated and, hence, is unique for each entry.

Add a few rows to the table so you can test your webapp. E.g.,

insert into Contact (LastName, FirstName, Phone1, Comments) 
    values ('University', 'York', '416-224-1833', 'Alma mater'); 
		

It is recommended that you enter the names — both first and last — in uppercase. This will facilitate search. Do a select to view your inserted rows. Verify that they have different IDs.

Design Outline

Your webapp consists of five files.

  1. pb.cgi

    • A shell script that launches the Java app.

  2. PBapp.java

    • An app whose main method contains new PB();.

  3. PB.java

    • The PhoneBook Webapp.

  4. PBdao.java

    • A class that implements the database connectivity.

  5. PBrow.java

    • A simple data structure to represent one row in the Contact table.

Start by developing PBrow. It should have five private attributes — the four mentioned in the requirements plus the ID — a getter and setter for each, and a default constructor that initializes the ID to -1, and the remaining attributes to empty strings.

Next, develop PBdao whose attributes must include a Statement object. Its constructor must connect to your database, and initialize the statement attribute. It must also have the method

public PBrow find(String entry)

This takes the entry made by the user in the search page, looks for it in the database — as described in the requirements — and returns the matching row. (The return should be null, if no match is found.)

The PB class acts as a controller that receives the incoming request, extracts the needed HTTP headers and parameters, and sequences the flow. It also includes methods for serving up the two pages.

The Implementation

Template implementations of some of the needed classes are available at

http://www.cse.yorku.ca/course/2041/lab4/

Start your implementation using these files, rather than start from scratch.

It is recommended that you use Eclipse as an IDE. To use Eclipse, click “Start, Programs, BlackBerry, EclipseEE Blackberry.” Once in Eclipse, create a new “Java Project”. Your home directory is mapped as drive Z, so create your workspace there.

 
  Lab Report

Leave your pb app active. Submit your java files.

submit 2041 lab4 PBapp.java PB.java PBdao.java PBrow.java