Friend Management App

Overview

In this personal project, I utilized the J2EE Model-View-Controller (MVC) design pattern to develop a web application for friend management. The application enables users to add new friends to the MySQL database by providing their details and through the backend input validation process. Additionally, users can view and delete any existing friend records as needed.

Functionalities include:

Source Code Link

Project Walk-Through

Block Diagram 1: Add_Friend Feature

This block diagram of the web application illustrates the process of inserting a new friend by incorporating the appropriate Servlet, Model, and View components.

Block Diagram 2: Delete_Friend Feature

This block diagram of the web application illustrates the process of deleting an existing friend by incorporating the appropriate Servlet, Model, and View components

(Model) Friends.java

Friends.java creates a model that generates an object for each friend, storing their specific details.

(Model) AddQuery.java

AddQuery is the class that interacts with the database. In the constructor of this class, a database connection is established. This means that when an AddQuery object is created, a connection to the database will be established automatically.

Functions in this class include adding a new friend using the Friends model (addNewFriend) and retrieving all friends' data from the database (readData). 

(Model) DeleteQuery.java

This class is similar to AddQuery class, but this class aims to delete a record based on a friend's ID.

(View) add.jsp

When the user accesses add.jsp through the URL or is redirected by the controller, a web form will be displayed. This form enables the user to enter information about a new friend, which will then be added to the database as a new friend entry if all data validation passed upon Submit.

(View) read.jsp

When the user accesses read.jsp through the URL, it will retrieve all rows from the friend table and display them in HTML format using JSTL (JavaServer Pages Standard Tag Library).

(Controller) Add.java

Upon creation, the servlet establishes a connection to the database using the AddQuery class we created earlier. 

The main purpose of this servlet is to retrieve data from the web form, save it into a Friends model, and then pass the model to the addNewFriend function of the AddQuery class.

(Controller) AddForm.java

When this servlet is called with a POST request, it will redirect the user to the add.jsp page where the user can enter a friend's details.

(Controller) Delete.java

This servlet is similar to Add.java. A database connection is established when the servlet is called, because of the constructor of the DeleteQuery class.

When a POST request is sent to this servlet, it retrieves the friendIdToDelete parameter from read.jsp and passes the ID to the deleteRecord function of the DeleteQuery class. 

Once the deletion is completed, the servlet redirects the user to the Read controller.

(Controller) Read.java

This controller redirects an user to read.jsp webpage.

Demonstration

Add a new friend -1

Launch the program, and click on Add a New Friend. The program will go through AddForm servlet, and call/redirect to add.jsp.

Add a new friend -2

Add friend's details and click on Submit.

Add and Display the updated friend's list

The program will go through Add servlet (to add the record), call Read servlet, and then call/redirect to read.jsp to display the updated list.

Delete a friend

After we added another two new friends, now we have a total of three friends. 

Delete the friend with ID 2 by clicking on Delete button next to it.

Delete and Display the updated friend's list

The program will go through Delete servlet (to delete the record), call Read servlet, and then call/redirect to read.jsp to display the updated list. 

Validation on Age -1

Server-side data validation on age: must be an integer.

Try entering details for another friend. Instead of using an integer in the age field, test by using a String: text.

Validation on Age -2

Program shows an error to the client.