Web-Based Online Voting System (JSP + Servlets + JDBC + MySQL)
A secure and structured online voting system built using Java Servlets, JSP, JDBC, and MySQL, following the MVC architecture. The system allows voters to register, log in, cast their vote once, and view results. Admins can manage candidates, voters, and monitor results.
π Features π€ Voter Module
Register and log in
Secure authentication
One-vote-per-user rule
Cast vote for available candidates
View voting confirmation
π οΈ Admin Module
Admin login
Add/manage candidates
View list of registered voters
View live election results
πΎ Backend
MySQL database
JDBC connection layer (DAO Pattern)
MVC-based architecture
Form validation & Session management
π Project Structure OnlineVotingSystem/ β βββ src/ β βββ dao/ # Database access objects β βββ servlets/ # Java Servlets (Admin, Voter, Voting) β βββ WebContent/ β βββ css/ # Style files β βββ WEB-INF/ β β βββ web.xml # Deployment descriptor β β βββ lib/ # MySQL JDBC driver β βββ *.jsp # JSP UI pages β βββ sql/ β βββ setup.sql # SQL script to create DB & tables β βββ README.md
βοΈ Technology Stack
Java (JDK 8β17 supported)
JSP / Servlets
MySQL (8.x)
JDBC
Tomcat 9 / 10
Eclipse IDE
π¦ Database Setup
Install MySQL Server
Open MySQL Shell / Command Line:
mysql -u root -p
Run the database setup script:
SOURCE sql/setup.sql;
π Configure Database in Project
Open:
src/dao/DBConnection.java
Update:
private static final String URL = "jdbc:mysql://localhost:3306/votingdb?useSSL=false"; private static final String USER = "root"; private static final String PASS = "YOUR_PASSWORD";
π₯ Add MySQL JDBC Driver
Download:
β‘οΈ mysql-connector-java-8.x.x.jar
Place it inside:
WebContent/WEB-INF/lib/
Or add to Eclipse Build Path.
π Run the Project In Eclipse:
File β Import β Existing Project into Workspace
Select the project root folder
Right-click project β Properties β Target Runtime β Add Tomcat
Right-click project β Run As β Run on Server
Project will start at:
http://localhost:8080/OnlineVotingSystem/
π§ͺ Testing the System Voter:
Register a new voter
Login
Cast a vote
Check results
Admin:
Default admin credentials (if included in SQL):
username: admin password: admin123
Admin Functions:
Add candidate
Manage candidates
View voter list
View result dashboard
π€ Upload/Push to GitHub git init git add . git commit -m "Initial commit - Online Voting System" git remote add origin https://github.com/YOUR_USERNAME/OnlineVotingSystem.git git push -u origin master
Not recommended for real-world election environments.
Password hashing is minimal/basic.