Home > Writing Samples > Coding Samples > AddressBook Final Project [CS 277]

AddressBook Final Project

December 2004


Partial image of AddressBook XML schema in XML Spy visual editing tool... click to enlarge... Specifications for the final project were fairly loose: we were told to use the AddressBook XML schema [AddressBook.xsd] that we had defined during the class and create a means (using Java) to enter and edit contacts into the XML file [AddressBook.xml] comprising the addressbook. [AddressBook.xml has a stylesheet, AddressBook.xsl, associated with it, as you'll see when you click the links.]


I implemented the project as JavaServer Pages (JSPs), parsing and managing the file as a DOM structure. The starting menu (ContactManagerHome.jsp) parses the AddressBook.xml and generates a list of names (first name, last name) from the addressbook. Next to each name is a link to Edit or Delete [these pages won't work properly, because my website hosting service doesn't support JSPs or Servlets, thus I'm showing the screenshots in this write-up; click on any image to see an enlargement.]

contact management system homepage One of the most challenging aspects of this project has been trying to tease out the data from the XML file. You'll see the convoluted shenanigans I had to go through to get the information about a particular contact out of the XML file, in this findContact.jsp program listing—this took most of my time, and would provide the basis for jsps to add and edit contact information, but I've not completed those yet. The difficulty lies in the somewhat open-ended XML Schema—there's a lot of latitude in what elements can comprise a "Contact."

For example, in some cases, a contact is married and has one or more children; in other cases not. Sometimes a person has a business and a work address; other times, not. I wanted the output to look decent, without empty values, and attaching labels to the data took an enormous amount of time.

children display at the top of the page Another issue was getting a contact's children to display properly in the output form. Quite simply, I couldn't get the Children to display in the output form where I wanted them to, so you'll see that if a contact has children, the names and birthdays are at the top of the output, rather than at the bottom as I'd like them to be, as in the Add contact HTML page.

The entire project is contained in the addressbook.war file. To deploy on Tomcat, simply drop this .war file into the Tomcat \webapps directory, and the directory (addressbook) will be created, and the files comprising the application will be put in the appropriate structures. Then restart the Tomcat server (on current releases of Tomcat, the restart is not necessary).

search page In addition to JSP, I also created an HTML front page (that closely resembles the JSP), but which calls a Servlet to provide the initial list of contacts from the addressbook. This is accessible on Tomcat at http://localhost/addressbook/contacts (assuming the .war file was deployed). As the AddressBook grows, it might be faster to access the simple HTML page and then search for a specific contact using the search feature.


result of search displays contact information One of the most difficult aspects of this assignment was choosing an approach, both in terms of the user interface (Swing components or Web-based, for instance) and the underlying mechanisms to deal with the XML file (DOM? SAX? JAXB? JDOM? XOM? and so on). In working through the project, I (unfortunately) went down a lot of dead ends. I thought that JAXB might have been the way to go, but it seemed more complicated to me than just dealing with the DOM structures.

If I had to start all over again at this point, I think that JDOM looks the most promising to use for something like this project. JDOM 1.0 was released just this past November [2004], and it looks a lot more straightforward to use than the DOM. However, it was too late for me to try to re-do everything using JDOM.

Updated Conclusion

In hindsight [2005], this project would have been perfect for an RDBMS rather than using XML. But as a learning exercise about how to implement Web Services using WSDL, SOAP, and learning something about XML Schema (and differences between that and DTD), it was an interesting project.