Advanced Programming and Technologies Assignment 1
Advanced Programming and Technologies Assignment 1
1. Introduction
In this assignment, you will develop a basic Contact Book Application that allows users to store and
manage their contacts. You will implement the fundamental CRUD (Create, Read, Update, Delete)
operations using JDBC for database connectivity, and create a simple user interface using Servlets and
JSP.
2.1 Model
Represents the data and business logic
Handles data storage, retrieval, and validation
Communicates with the database
In this assignment: Java classes that represent contacts and handle database operations
2.2 View
Presents the data to users
Handles the user interface
In this assignment: JSP pages that display forms and contact information
2.3 Controller
Processes user input
Coordinates between Model and View
In this assignment: Servlets that handle HTTP requests and responses
3. Project Requirements
1. Contact Management
Add new contacts with basic details (name, phone, email, address)
View a list of all saved contacts
View details of a specific contact
Update contact information
Delete contacts
Search for contacts by name
2. User Interface
2. Application Structure
3. Java Technologies
ContactBookApp/
├── src/
│ └── main/
│ ├── java/
│ │ ├── model/
│ │ │ ├── Contact.java
│ │ │ └── ContactDAO.java
│ │ └── controller/
│ │ └── ContactServlet.java
│ └── webapp/
│ ├── WEB-INF/
│ │ └── web.xml
│ ├── view/
│ │ ├── contact-list.jsp
│ │ ├── add-contact.jsp
│ │ ├── edit-contact.jsp
│ │ └── view-contact.jsp
│ └── css/
│ └── style.css
└── pom.xml (or build.gradle)
5. Implementation Guide
package model;
package model;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class ContactDAO {
private Connection connection;
5.3 Controller Layer
The Controller layer will consist of servlets that handle HTTP requests:
package controller;
import model.Contact;
import model.ContactDAO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/contacts/*")
public class ContactServlet extends HttpServlet {
private ContactDAO contactDAO;
if (action == null) {
action = "/list";
}
switch (action) {
case "/new":
showNewForm(request, response);
break;
case "/edit":
showEditForm(request, response);
break;
case "/delete":
deleteContact(request, response);
break;
case "/view":
viewContact(request, response);
break;
default:
listContacts(request, response);
break;
}
}
if (action == null) {
action = "/list";
}
switch (action) {
case "/insert":
insertContact(request, response);
break;
case "/update":
updateContact(request, response);
break;
default:
listContacts(request, response);
break;
}
}
<div class="search-box">
<form action="contacts/list" method="get">
<input type="text" name="search" placeholder="Search by name...">
<button type="submit">Search</button>
</form>
</div>
<table>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Actions</th>
</tr>
<c:forEach var="contact" items="${contactList}">
<tr>
<td><c:out value="${contact.name}" /></td>
<td><c:out value="${contact.phone}" /></td>
<td><c:out value="${contact.email}" /></td>
<td>
<a href="contacts/view?id=<c:out value='${contact.id}' />">View</a>
<a href="contacts/edit?id=<c:out value='${contact.id}' />">Edit</a>
<a href="contacts/delete?id=<c:out value='${contact.id}' />"
onclick="return confirm('Are you sure you want to delete this contact?
</td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
6. Step-by-Step Implementation Guide
1. Project Overview
2. System Architecture
3. Screenshots
4. Testing
5. Reflection
8.2 Servlets
Servlets are Java classes that handle HTTP requests and generate responses. Key points:
2. Documentation Submission
3. Deadline
Good luck with your assignment! Remember to start early and ask for help if you need it.