Skip to content

DAO Pattern Presidents

This project, DAOPatternPresidents, uses a PresidentDAO that connects to a database.

You will be adding code to an existing servlet, and manually testing the site with a mock DAO (no JUnit tests).

Setup

  1. Download DAOPatternPresidents.zip and import it into Eclipse

  2. Load the database.

DAOPatternPresidents/DBSETUP.txt * Follow the instructions in this file to load the historydb database.

Existing Functionality

This PresidentDAO has four methods: * List<President> getPresidents() * President getPresidentByTermNumber(int number) * List<President> findByParty(String string) * List<President> findByLastName(String string)

The index.html page contains two forms and one link. All requests go to /presidentInfo, but the servlet will return different information, depending on the request parameters.

Lab

You will be adding code to com.example.servlets.PresidentServlet, and first testing it with a mock DAO.

  1. Servlet functionality:
  2. If party is present in the request and not empty, display an unordered list of the full names of presidents of that party.
  3. If lastName is present in the request and not empty, display an unordered list of the full names of presidents with that last name.
  4. If termNumber is present in the request and not empty, display that president's full data. (Only display the president's full data when termNumber is requested.)
  5. If all request parameters are null or an empty string, display all presidents' full names as an unordered list.

  6. Additionally, each full name displayed via party, lastName, or no request parameters must be an HTML link to presidentInfo?termNumber=TERM_NUMBER, where TERM_NUMBER is that president's term number.

  7. In com.example.data.president, create a MockPresidentDAO with three President objects stored in a List<President> instance field.

  8. These President objects should satisfy test criteria, such as two having the same last name, two having the same party, and all having a different term number.
    • Methods, such as getPresidentByTermNumber, will use the instance field to find the requested President.
  9. Set your servlet to use an instance of this class in the init() method.
  10. Test your application's functionality.

  11. Now change the servlet to use JDBCPresidentDAOImpl and retest the application.


Up