β Project Overview.
π― Goal: A system where:
Employers and Workers can register and log in.
Employers can post jobs.
Workers can view jobs and apply.
π Project Structure
EmployerWorkerSystem/
βββ π src/
β βββ π com.system/
β βββ π controllers/
β β βββ LoginServlet.java
β β βββ LogoutServlet.java
β β βββ RegisterServlet.java
β β βββ ApplyJobServlet.java
β β βββ PostJobServlet.java
β β βββ UpdateStatusServlet.java
β β βββ UploadResumeServlet.java (optional)
β βββ π utils/
β β βββ DBUtil.java
β β βββ EmailUtility.java
β βββ π models/
β βββ User.java
β βββ Job.java
β βββ Application.java
β
βββ π WebContent/ (or webapp/)
β βββ π css/
β β βββ style.css
β βββ π js/
β β βββ app.js
β βββ π uploads/ <-- Uploaded images/resumes go here
β βββ π jsp/
β β βββ login.jsp
β β βββ register.jsp
β β βββ employer_dashboard.jsp
β β βββ worker_dashboard.jsp
β β βββ post_job.jsp
β β βββ available_jobs.jsp
β β βββ manage_applicants.jsp
β β βββ worker_applied_jobs.jsp
β β βββ profile.jsp
β β βββ error.jsp
β βββ index.jsp
β
βββ π META-INF/
βββ π WEB-INF/
β βββ web.xml
β βββ lib/ (if not using Maven: put JDBC, JavaMail JARs here)
β
βββ π pom.xml (if using Maven)
βββ π README.md
π§Ύ Database Tables Example (MySQL/PostgreSQL).
-- User Table (Employer or Worker)
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100),
email VARCHAR(100),
password VARCHAR(100),
role ENUM('employer', 'worker')
);
-- Jobs (Posted by Employers)
CREATE TABLE jobs (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
description TEXT,
employer_id INT,
FOREIGN KEY (employer_id) REFERENCES users(id)
);
-- Applications (Submitted by Workers)
CREATE TABLE applications (
id INT AUTO_INCREMENT PRIMARY KEY,
job_id INT,
worker_id INT,
FOREIGN KEY (job_id) REFERENCES jobs(id),
FOREIGN KEY (worker_id) REFERENCES users(id)
);
π§ Core Servlets.
RegisterServlet.java
β Handles user registration.
LoginServlet.java
β Handles authentication and session.
PostJobServlet.java
β Employer posts a job.
ApplyJobServlet.java
β Worker applies for job.
π Example: Registration Form (HTML/JSP)
<form action="RegisterServlet" method="post">
<input type="text" name="username" placeholder="Username" required><br>
<input type="email" name="email" placeholder="Email" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<select name="role">
<option value="employer">Employer</option>
<option value="worker">Worker</option>
</select><br>
<button type="submit">Register</button>
</form>
π Tips.
Store passwords hashed (e.g., using SHA-256).
Use sessions to manage login state.
Validate inputs both on client (JS) and server (Servlet).
Show different dashboards for employer vs. worker.
π After Form Submission.
The form will send data to your RegisterServlet, where you'll handle:
Validating input
Inserting user into the database
Redirecting to login or dashboard
π§© Next Steps.
Make sure your web.xml
or annotations register this servlet.
Test the form and ensure the data is inserted into the database.
Add a login.jsp
and LoginServlet.java next for authentication.
π Optional: Secure with Session Filters.
π§© How to Use.
In your dashboard pages (e.g. employer_dashboard.jsp, worker_dashboard.jsp), include a logout link:
<a href="../LogoutServlet">Logout</a>
π‘οΈ Optional: Session Check Snippet in JSP.
To protect pages from unauthorized access, add this at the top of protected JSPs:
<%
String user = (String) session.getAttribute("username");
if (user == null) {
response.sendRedirect("../login.jsp");
}
%>
π§© Let's implement the Job Posting feature for employers in your system.
This feature will include:
A JSP form (post_job.jsp)
to enter job details
A Servlet (PostJobServlet.java)
to handle form submission
A MySQL table to store job posts.
β 1. Create the jobs Table.
Make sure your database has this table:
CREATE TABLE jobs (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
employer_id INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (employer_id) REFERENCES users(id)
);
β 2. JSP Form: β 3. Servlet:
π§ IMPORTANT β Track userId on Login. Update your LoginServlet to store the user's ID:
int userId = rs.getInt("id");
session.setAttribute("userId", userId);
π§© Overview,
This will include:
A job listing JSP for workers
A button/form to apply for a job
A new database table to store applications
An ApplyJobServlet
to handle applications
β 1. Create job_applications Table.
In your MySQL database:
CREATE TABLE job_applications (
id INT AUTO_INCREMENT PRIMARY KEY,
job_id INT NOT NULL,
worker_id INT NOT NULL,
applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (job_id) REFERENCES jobs(id),
FOREIGN KEY (worker_id) REFERENCES users(id)
);
β
2. JSP Page: job_list.jsp
.
This lists jobs and shows an βApplyβ button for each job. Add a check so only workers can access it.
β
3. Servlet: ApplyJobServlet.java
β 4. Add Link to Job List (from dashboard).
On worker_dashboard.jsp
, link to the job listing:
<a href="job_list.jsp">Browse Jobs</a>
π§© Feature Overview.
JSP page: view_applicants.jsp
Fetch applicants for jobs posted by the logged-in employer
Display job title and list of workers who applied
β 1. JSP Page.
β
2. Add Link in employer_dashboard.jsp
:
<a href="view_applicants.jsp">View Applicants</a>
π§© What's Included:
Update the job_applications
table to include a status
field
Modify the ApplyJobServlet to set default status
Create a JSP page for employers to update application status
Create a JSP page for workers to view their applied jobs with status
β 1. Update job_applications Table.
Run this SQL to add a status column:
ALTER TABLE job_applications ADD COLUMN status VARCHAR(20) DEFAULT 'Pending';
β
2. Modify ApplyJobServlet.java
Add this line when inserting application:
String sql = "INSERT INTO job_applications (job_id, worker_id, status) VALUES (?, ?, 'Pending')";
β
3. JSP: manage_applicants.jsp
(Employer View).
β
4. UpdateStatusServlet.java
.
β
5. worker_applied_jobs.jsp
β Worker View,
β 6. Add Links in Dashboards.
In employer_dashboard.jsp
:
<a href="manage_applicants.jsp">Manage Application Status</a>
*In worker_dashboard.jsp
:
<a href="worker_applied_jobs.jsp">My Applications</a>
π§© Goal.
When an employer changes the status of an application, the worker gets an automated email notification.
β Steps:
Configure JavaMail in your project
Update UpdateStatusServlet
to send an email after updating
Create an EmailUtility
class for reusable mail sending
β 1. Add JavaMail Dependency.
If using Maven, add this to pom.xml
:
If not using Maven, download javax.mail
jar and add it to your projectβs lib
folder.
β
2. EmailUtility.java
(Utility Class).
β
3. Modify UpdateStatusServlet.java
.
After updating status in DB, fetch worker email and send email:
β Key Features Included.
User Registration & Login: Separate flows for employers and workers.
Job Posting: Employers can post job listings.
Job Application: Workers can apply to jobs.
Application Status Management: Employers can update application statuses; workers can view them.
Image Upload: Users can upload profile images during registration.
Email Notifications: Workers receive emails upon status updates.
π Getting Started.
Database Setup:
Create a MySQL database named employer_worker_system
.
Execute the provided schema.sql
script to create necessary tables.
Configure Database Connection:
Update DBUtil.java
with your database URL, username, and password.
Build and Deploy:
If using Maven, run mvn clean install
.
Deploy the WAR file to your servlet container (e.g., Apache Tomcat).
Access the Application:
Navigate to http://localhost:8080/EmployerWorkerSystem/
in your browser.
π¦ The Project Template