You are on page 1of 117

T.Y.B.Sc.

IT Project title here

1
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Chapter 1: INTRODUCTION

Online voting system using Fingerprint is a web application where the user is
recognized by his finger pattern. Since the finger pattern of each human being is
different, the voter can be easily authenticated. The system allow the voter to vote
through fingerprint. Fingerprint is used to uniquely identify the user. The Fingerprint
minutiae features are different for each human being, voter can vote the candidate
only once and the system will not allow the candidate to vote for the second time. The
system will allow admin to add the candidate name and candidate party symbol who
are nominated for the election.
Admin only has the right to add candidate name and symbol who are nominated. The
number of candidate added to the system by the admin will be deleted after the
completion of the election. Admin has to add the date when the election going to end.
Once the user has got the user id and password then the user can login and vote for the
candidate who are nominated. The system will allow the user to vote for only one
candidate. The system will allow the user to vote for one time for a particular election.
Admin can add any number of candidates when the new election will be announced.
Admin and user can view the election result.

Background

In recent years, the use of biometric technologies has become increasingly popular for
authentication and identification purposes. Fingerprint recognition is one such
technology that has gained significant traction due to its accuracy, reliability, and ease
of use. With the aim of providing a secure and efficient voting system, I have
developed an online voting system that uses fingerprint recognition during the online
registration of user.This system leverages JavaServer Pages (JSP) and Servlet
technologies to enable voters to register and cast their votes with ease and
convenience. By eliminating the need for traditional registration methods, such as
filling out forms for providing personal information.

2
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Objectives

- Ensuring the security of the website and the voting process, including
protecting against hacking, fraud, and other forms of manipulation.

- Providing a user-friendly interface that is easy to navigate and understand, even


for voters who may not be tech-savvy.

- Offering multiple authentication methods to ensure that only eligible voters can
cast their votes.

- Allowing voters to cast their votes at any time, from anywhere, as long as they
have access to the internet.

- Providing accurate and timely results that can be easily verified by


independent auditors.

PURPOSE, SCOPE, APPLICABILITY

Purpose

The purpose of the online voting system using fingerprint is to make web based
secured online portal and user- friendly for the all common people without nominal
knowledge about the voting.

The main purpose of the system:-

Planned approach towards working:-


The working of system will be well planned and organized. The data will be stored
properly in database which will help to retrieval of information as well as its storage.
Accuracy:-
The level of accuracy in the proposed system will be higher. All operation would be
done correctly and it ensures that whatever information is coming from the center is
accurate.
Reliability:-
The reliability of the proposed system will be high due to the above stated reasons.
The reason for the increased reliability of the system is that now there would be
proper storage of information.

3
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

No Redundancy:-
In the proposed system utmost care would be that no information is repeated
anywhere in storage space and consistency in the data stored.
Easy to operate:-
The system should be easy to operate and will have a very friendly user interface so
that the user can feel very easy to work on it.
Cost Managing:-
The system should be such that it can be developed within a short period of time and
fit in the limited budget by replacing all the manual work with the computer based
system.

Scope

- The Online Voting System Using Fingerprint provides an end-to-end solution


for conducting online elections or polls.

- It allows users to create and manage polls, set voting rules and regulations, and
invite voters to participate.

- The system ensures the security of the voting process by implementing


strict authentication and authorization protocols.

- It also provides real-time tracking and monitoring of the voting process,


allowing administrators to identify and address any issues promptly.

Applicability

The Online Voting System Using Fingerprint is suitable for use in a wide range of
applications, including academic institutions, government organizations, and corporate
entities. It can be used to conduct various types of polls or elections, such as student
council elections, board member elections, and shareholder meetings. The system is
scalable and can handle large volumes of users and data, making it suitable for use in
organizations of any size. Additionally, the system's user-friendly interface makes it
accessible to voters of all ages and technical backgrounds.

4
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

5
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Chapter 2: SURVEY OF TECHNOLOGY

2.2 Advance Java:-

1) JSP (JavaServer Pages):

- JSP is a server-side scripting language that is used to create dynamic web


pages.

- JSP files can contain HTML, Java code, and other types of content that are
processed by a web container (such as Apache Tomcat) to generate a response
to a client's request.

2) Servlets:

- A servlet is a Java class that runs on a web server and handles client
requests.

- Servlets are typically used to process and respond to HTTP requests, such
as those sent by a web browser.

- Servlets can be used to generate dynamic content, interact with databases,


and perform other server-side tasks.

3) JSTL (JavaServer Pages Standard Tag Library):

- JSTL is a library of custom tags that can be used in JSP files to simplify
the development of dynamic web pages.

- JSTL provides tags for common tasks such as looping over collections,
formatting dates and numbers, and conditionally displaying content.

4) MVC (Model-View-Controller) architecture:

- MVC is a software design pattern that is commonly used in web development.

- The MVC pattern separates an application into three main components: the
model (which represents the data and business logic), the view (which displays
the data to the user), and the controller (which handles user input and updates
the model and view).

6
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

MySQL: -

1) MySQL Connector/J:

- MySQL Connector/J is the official JDBC driver for MySQL.

- It provides a high-performance, type 4 JDBC driver that can be used to connect


to MySQL databases from Java applications.

- The driver is available for download from the MySQL website.

2) Apache Derby:

- Apache Derby is a lightweight, open-source relational database management


system that is written in Java.

- Derby provides a small footprint and can be embedded in Java applications.

- Derby can be used as a replacement for MySQL in Java applications where


a lightweight, embedded database is required.

7
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

8
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Chapter 3: REQUIREMENTS AND ANALYSIS

Problem Definition

In the recent years there are many literature on online voting has been developed.
While online voting has been an active area of research in the recent years, effort to
develop real-world solutions have just begun posing several new challenges. The use
of insecure Internet, well documented cases of incorrect implementations and the
resulting security breaches have been reported in past. These challenges and concerns
have to be resolved in order to create public trust in online voting. Online voting
system will provide the online registration form for the users before voting and
makes the user to cast their vote online. The system is to be developed with high
security by taking fingerprint of each voter and make system more user-friendly.

Requirements Specification

The purpose of the requirements analysis is to identify requirement for the proposed
system. The emphasis is on the discovery of user requirements. Each requirement
must be defined and documented.

Following are the requirement specification:-

 Admin should be able to insert or update candidate information.

 Admin should organize Election and give particular date and time for election.

 Voter information with fingerprint should store in database.

 Voter can vote only one time and can vote only one candidate.

 Admin should declare results.

 Admin and Voter can view the results.

9
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Planning and Scheduling

Gantt Chart

10
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Pert Chart

11
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Software and Hardware requirements

 Hardware requirements:

- Processor: intel 3 / Ryzen 3 (Quad Core, Dual-Core or


better recommended).

- Processor Speed: 1.8 GHz or Faster Processor RAM- 2 GB RAM or above.

- Hard Disk: 120 GB hard disk or above.

- Graphics Card: Video card that supports a minimum display resolution of 720p.

- Fingerprint Scanner

 Software Requirements:

- Window 7/8/8.1

- 32/64 operating system

- NetBeans 8.2 for Advance Java

- MySQL JDBC Driver for MySQL

- A compatible browser for running the project

12
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Preliminary Product Description

The product is an election conducting tool with a simple GUI in it. This system is
developed using Advance Java and MySQL. This product is stand-alone. It requires a
back-end server which can be done by NetBeans application by connecting MySQL
JDBC Driver. Our system has a server back-end which takes care of authenticating the
users and maintaining necessary details. The user interface at the server end creating
the election on behalf of the users. The user must login with id and password then they
can access the election module where they can cast their vote with such ease and
comfort and their response will be saved and after the result will be displayed.

The system will ensure the points below are achieved:

 Voter Register

 Secured User verification system

 Voter verification

 Authentication of voters

 Avoiding of election of malpractices such as: over voting.

 Fast, easy and reliability.

 Result will be displayed fast and accurate because all the work is computer-based

13
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Conceptual Models

Event Table

Event Trigger User-case Service Response Destination

Admin/Voter Login Manage Voter/Admin Successful Admin/Voter


Login Account /Failed

View/Update Request for Manage Admin/Voter Profile Admin/Voter


Profile viewing or Profile update
updating
profile

Candidate Registering Manage Admin Successful Admin


Register the candidate register/failed
candidate
Election Conducting Manage Admin Election Admin
the Election Election Generated

View Viewing Manage Admin/Voter Successful Admin/Voter


Candidate candidate Candidate Generated
information

Cast voting Page for Manage Voter Successful Voter


casting the Voting voted/failed
vote

Result Viewing Manage Admin/Voter Result Admin/Voter


Result Result

14
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

3.2.6 ER Model

15
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Use-Case Diagram

Online voting system using Fingerprint

Register

Login

Add/Update Candidate

Admin

View Candidate
Voter

Add/update Election

Manage Result

Cast Vote

View Result

Logout

16
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Class Diagram

17
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Sequence Diagram

18
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

3
]p

State Diagram StSatratrt

Register Voter
No

Is voter
register?

Yes

Voter login

Show error message

Username
Register login error password correct?

Yes

Vote candidate

Vote No
successful?

Display system error message


Save to database

Update vote count


Redirect to voter profile

Show confirmation End

19
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Activity Diagram

Admin:
Voter:

Authentic Admin
Authentic Admin user and password
user and password

Not valid Not


valid
Check
Check validity
validity

Valid

View Voter profile

Add Candidate Add Election


Already yes
Vote Inform voter
can’t vote

Logo Show list of candidate


Save vote Select Candidate No
data/update voter
confirm

Save candidate data


and his vote
Vote Casted

20
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

21
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Basic Modules

1. Administration Module:-
In this module admin have authority to stores the user information, providing
registration and performing the adding, deleting, updating the candidate and election
information. Admin gives the data for voting process in the particular date specified.

2. Registration Module:-
In this module the voters has to do registration for performing the voting process
through online. Once the registration is completed the admin approves the voters for
voting process. So the users can login and vote for the candidate. The user registration
is performed for security purpose.

3. Voting module:-
In this module voters have the provision to view the list of candidate who are
nominating for the election. So they can vote for the candidate through online. The
voting process can be done only once and for limited time.

4. Fingerprint Module:-
In this module the system allow the voter to vote through his fingerprint as the
fingerprint of each human being is different the voter can be easily authenticated the
login will be successful only when the user fingerprint matches to vote their cast.

5. Security Module:-
In this module Auto-logout feature take care of the rest, after a vote has been placed
and the main login screen is restored. So that the duplicate vote can be avoided only
one vote can be created by a single user. So it will be more secure and efficient.

6 .Counting Module:-
In this module counting is performed. The vote acquired by each candidate will be
displayed. Total number of votes for each candidate is calculated and displayed. The
candidate with maximum vote is awarded as winning candidate.

7. Result Module:-
In this module the admin get the final report of the voting. The candidate with higher
vote is displayed as winning candidate. The details regarding the voting process will
be stored in the database for future reference.

22
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Data Design

Schema Design with Data Integrity and Constraints

1. Primary Key Constraint:

Primary Key Constraint uniquely identifies each record in the database. A


Primary Key must contain a unique value and it must not contain a null value.

2. Foreign Key Constraint:

Foreign Key is a field (or collection of fields) in one table, that refers to the
PRIMARY KEY in another table. The table with the foreign key is called the
child table, and the table with the primary key is called the referenced or parent
table.

3. Not Null Constraint:

Not Null Constraint makes sure that a column is not left null. It forces the
person to enter some value else it will show an error.

4. Unique Constraint:

Unique Constraint the name itself suggests that a column will have a unique
value. This constraint makes sure that columns don’t have any duplicate
values.

5. Auto Increment:

The Constraints applied to whichever column will see that it increments itself
whenever a new record is inserted so that the duplication is not generated.

23
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

1. Admin Table

Column Name Data Types Constraints

Username Varchar (25) Not Null

Password Varchar (25) Not Null

2. Voter Table

Column Name Data Types Constraints

ID Int Auto-Increment

Voter Varchar(25) Primary Key

Name Varchar(25) Not Null

Username Varchar(20) Not Null

Pass Varchar(15) Not Null

Email Varchar(20) Not Null,Unique

Date Date Not Null

Contact Int Not Null

Address Varchar (40) Not Null

Photo Blob Not Null

Gender Bool Not Null

ANSI Long text Not Null

24
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

3. Candidate Table

Column Name Data Types Constraints

ID Int Primary Key,Auto-Incrment

Name Varchar (25) Not Null

Email Varchar (40) Not Null

Date Date Not Null

Address Varchar(50) Not Null

Contact Int Not Null

File Blob Not Null

Gender Bool Not Null

4. Election table

Column Name Data Types Constraints

EID Int Primary Key,Auto-Incrment

EName Varchar (25) Not Null

CID Int Not Null,Unique

Name Varchar(25) Not Null

Email Varchar (40) Not Null

Date Date Not Null

25
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Address Varchar(50) Not Null

Contact Int Not Null

File Blob Not Null

Gender Bool Not Null

Edate Date Not Null

Vote Int Not Null

5. Votes Table

Column Name Data Types Constraints

Username Varhcar(40) Not Null

Ename Varchar (40) Not Null

26
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Data Relationship Design

Admin
Username:varchar(25) Password: Varchar (25)
Candidate
ID:Int
Name: Varchar (25)
Email: Varchar (40) Date: Date
Address: Varchar(50) Contact: Int
File: Blob Gender :Bool

Voter
VoterID:int Name:varhcra(25) Username:varchar(20) Pass:varchar(15) Email:varchar(20) Date:date
Contact:int Address:varchar(40) Photo:Blob Gender:bool Ansi:long text

Election
Ename:Varchar(20) Cid:int Name:varchar(25) Email:varch
Vote:int

Votes

Uname:varchar(40) Ename:varhar(40)

27
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Security Issue

Most online voting systems claim to be secure referring to cybersecurity and


resistance to cyberattacks. However, this is not enough. A voting system is secure in
the sense that we can trust that the results of an election are fair and correct while
protecting voters’ privacy. This is challenging because a voter must be able to trace
the effect of her vote on the result, while on the other hand privacy requires that a vote
cannot be traced back from the result to a voter.
The expression has different meanings depending on context. On one hand, we can
speak about secure voting in the general context of cybersecurity. On the other, secure
voting has more specific definitions in the academic research literature into voting
systems. In a general context, secure voting is understood to be about methods,
software and systems that aim to protect an election from fraud and disruption. It a
question of correctness and integrity. A voting system is secure in the sense that we
can trust that the results of an election are fair and correct. The main threats faced by a
secure voting system are those typical of any computer security problem: hacking,
intrusion, manipulation, disruption. If we restricted our discussion to this general
context, secure voting would be “just” another problem in cybersecurity.

The goals of secure voting are described by:

 The term “secure voting” is generally thought to refer to cybersecurity and


resistance to cyberattacks.
 However, cybersecurity is a general property of hardware/software that does
not reflect the specific requirements of voting as a political process. The secret
ballot is an established and indispensable requirement for voting.
 Secure voting systems must support privacy as well as integrity; these
two requirements stand in opposition.
 In a system supporting privacy, no one, not even system administrators or
other privileged observers can violate the secret ballot.
 In a system supporting end-to-end verifiability, voters can ensure that their vote
was cast, recorded, and counted correctly.

A secure voting system is an end-to-end verifiable voting system that also employs
general computer security principles.

28
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

29
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Chapter 5: Implementation and Testing

Implementation approachesI

 (Admin)LogIn Page:

Description:

This is admin login page where admin have to give username and password to access
the website. Correct login credentials redirect them to their respective portal, while
incorrect passwords display an error message ('Incorrect Password. Please try again.').
Unique email-ID and password combinations ensure secure access to the voting
system for authorized personnel."

30
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Admin Home Page

Description:

When Admin will login successfully then home page will open. In this page you can
see various option like :-
Add Candidate: Add a new candidate to the list of candidates for the upcoming
election.
Manage Candidate: Update or delete the details of a candidate that has already been
added.
Add Election: Generate a new election and specify theend dates and the type of
election.
Result Declaration: Announce the final results of the election based on the vote count.
Logout: Log out of the system and end the current session.

31
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Add Candidate

Description:

This feature enables the admin to add a new candidate to the list of candidates for the
upcoming election. The admin can enter the candidate's name, party symbol, and other
relevant details. This makes it easy for the administrator to manage the list of
candidates and ensures that voters have access to up-to-date information on who they
can vote for.

32
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Manage Candidate

Description:

This is Manage Candidate page which allows the admin to update or delete the details
of a candidate that has already been added. The admin can edit the candidate's name,
party affiliation, or any other relevant details. Additionally, the admin can also delete
a candidate from the list if required.

33
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Add Election

Description:

This is Add election page which allows the admin to generate a new election and
specify te end dates for the election. The admin can also specify the type of election
such as presidential or parliamentary and add as many candidates as required.Admin
can also delete the candidate name from election list.

34
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Result

Description:-

This is Result Page in which admin can view the winner of particular election by
selecting election topic or name in select tag and click on view result .After that
admin can view the list of candidate who was register for specified election ,It show
candidate id,name and number of vote he/she got.

35
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 (User)Login Page

Description:-

This page includes a user login page with a forget password feature and a registration
link. Users can securely log in using their unique username and password, and in case
they forget their password, they can easily reset it using the forget password feature.
Additionally, new users can register themselves through the registration link to gain
access to the voting system.

36
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Register Page

Description:-

The registration page allows new users to sign up and create their account. It includes
fields for entering personal information such as name, email address, photo,fingerprint
and a unique username and password for secure login. After filling out the required
details and submitting the registration form, users can access the voting system and
participate in the voting process.

37
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 User Home Page

Description:

This page is user home page which have many option like:

View Candidate:-User can view the candidate who is standing for particular election
Result:-In this page user can view the election result after the election is completed
View Profile:In this page user can view their profile and can also update the profile
AboutUs:-This page allow the user to give information of about the website and give
feedback or any query throught gmail.

38
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 View Candidate :

Description:

In this page user can view the candidate for particular election and give vote user can
give vote only one time for particular election .If he/she has given vote in particular
election then he/she cannot view the candidate.

39
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Result Page:-

Description:

In Result Page user can view the result of particular election result will only declared
after the end date or completion of election.

40
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 About Us

Description:-

This is Aboutus page where user can give feedback or he/she have any query related
to website.This page give information about the website.

41
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Coding Details and Coding Efficiency


 Admin(Login)
 Component Table

Sr .No Component Component Name Code Value


1 Text Username textid
2 Password Password pwd
3 Submit Login Submit

 Admin.jsp

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Online Voting System</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel='stylesheet'
href='newcss.css'
type='text/css'
media='all'>
<script src="https://kit.fontawesome.com/a076d05399.js"
crossorigin="anonymous"></script>
</head>
<body>
<header class="site-header">
<div class="site-identity">
<a href="#"><img src="images/logo.png" alt="Site Name" width="140px"
height="70px"/></a>
<h1 style="color:white;"><a href="#">Online Voting System</a></h1>
</div>
<nav class="site-navigation">
<ul class="nav">
<li><a href="index.html">Admin</a></li>
<li><a href="userlogin.jsp">Voter</a></li>

</ul>
</nav>

42
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

</header>

<br><br><br><br><br><br>
<center>

<div class="wrapper">
<div class="title"><span>ADMIN LOGIN PANEL</span></div>
<form action="login" method="post">
<div class="row">
<i class="fas fa-user"></i>
<input type="text" placeholder="Username" name="textid" required>
</div>
<div class="row">
<i class="fas fa-lock"></i>
<input type="Password" placeholder="Password" name="pwd" required>
</div>
<div class="row button">
<input type="submit" value="Login">

</div>
</form>
</div>

</body>
</html>

 Login.java

package mypack;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class login extends HttpServlet {

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

43
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

throws ServletException, IOException {


response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
String uname=request.getParameter("textid");
String upass=request.getParameter("pwd");
if(uname.equals("admin") && upass.equals("admin@123"))
{
HttpSession hs=request.getSession();
hs.setAttribute("uname",uname);
response.sendRedirect("Home.jsp");
}
else
{
out.println("<script type=\"text/javascript\">");
out.println("alert('User or password incorrect');");
out.println("</script>");
RequestDispatcher rd=request.getRequestDispatcher("index.html");
rd.include(request, response);
}
}

44
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Login Page
 Component Table

Sr .No Component Code Value Component


Name
1 Text textid Username
2 Password pwd Password
3 HyperLink - ForgetPassword
4 Submit Submit Login
5 HyperLink - Register Here

Logincheck.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mypack;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
*
* @author khadk
*/
public class logincheck extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
String uname=request.getParameter("textid");
String upass=request.getParameter("pwd");

45
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

if(LoginDao.validate(uname, upass)){
HttpSession hs=request.getSession();
hs.setAttribute("uname",uname);
RequestDispatcher rd=request.getRequestDispatcher("userhome.jsp");
rd.forward(request,response);
}
else{
out.println("<script type=\"text/javascript\">");
out.println("alert('User or password incorrect');");
out.println("</script>");
RequestDispatcher rd=request.getRequestDispatcher("userlogin.jsp");
rd.include(request,response);
}
out.close();
}
}

LoginDao.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mypack;
import java.sql.*;
public class LoginDao {
public static boolean validate(String name,String pass){
boolean status=false;
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con
=DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");
PreparedStatement ps=con.prepareStatement( "select * from REGISTER
where UNAME=? and PASS=?");
ps.setString(1,name);
ps.setString(2,pass);
ResultSet rs=ps.executeQuery();
status=rs.next();

}catch(Exception e){System.out.println(e);}
return status;
} }

46
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 (User)Register Page

 Component Table

Sr .No Component Component Name Code value


1 Label VoterId txtvoter
2 Label Name txtname
3 Label Username txtid
4 Label Email txtemail
5 Label Password txtpass
6 Label DOB txtdob
7 Label Address txtaddr
8 Label Contact txtcon
9 Label File txtfile
10 Label Gender gender
11 Button Capture btncapture
12 Label ANSI Base64Encoded
ANSI
13 Button Register submit

Registerstore.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mypack;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;

47
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

/**
*
* @author khadk
*/
@MultipartConfig(maxFileSize=16177216)
public class registerstore extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

String voter=request.getParameter("txtvoter");
String fname=request.getParameter("txtname");
String id=request.getParameter("txtid");
String email=request.getParameter("txtemail");
String pass=request.getParameter("txtpass");
String dob=request.getParameter("txtdob");
String aadr=request.getParameter("txtaddr");
String cont=request.getParameter("txtcon");
Part part=request.getPart("txtfile");
String gend=request.getParameter("gender");
String AnsiTemplate=request.getParameter("Base64EncodedANSI");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con
=DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");
PreparedStatement pst=con.prepareStatement("insert into REGISTER
values(DEFAULT,?,?,?,?,?,?,?,?,?,?,?)");
InputStream is=part.getInputStream();

pst.setString(1,voter);
pst.setString(2,fname);
pst.setString(3,id);
pst.setString(4,email);
pst.setString(5,pass);

48
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

pst.setString(6,dob);
pst.setString(7,aadr);
pst.setString(8,cont);
pst.setBlob(9,is);
pst.setString(10,gend);
pst.setString(11,AnsiTemplate);
int i=pst.executeUpdate();
if(i>0)
out.println("<script type=\"text/javascript\">");
out.println("alert('You are successfully registered...');");
out.println("</script>");
RequestDispatcher rd=request.getRequestDispatcher("register.jsp");
rd.include(request, response);
}
catch(Exception e)
{
out.println(e);
}

49
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 AdminNavigation Page

 Component Table

Sr .No Component Component Name Code value


1 HyperLink Home -
2 HyperLink Add Candidate -
3 HyperLink Manage Candidate -
4 HyperLink Result -
5 HyperLink Logout -

Adminhead.jsp

<%--
Document : Home
Created on : 19 Jan, 2023, 2:40:26 PM
Author : khadk
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ADMIN PAGE</title>
<link rel='stylesheet'
href='home.css'
type='text/css'
media='all'>
</head>
<body>
<%
if(session.getAttribute("uname")==null)
{
response.sendRedirect("input.html");
}
%>
<header class="site-header">
<div class="site-identity">
<a href="#"><img src="images/logo.png" alt="Site Name" width="140px"
height="70px"/></a>
<h1 style="color:white;"><a href="#">Online Voting System</a></h1>
</div>

50
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

<div class="nav-header">

<img src="images/adminlogo.jpg" alt="Site Name" width="50px"


height="50px"/>
<h3> <%=session.getAttribute("uname")%> Panel</h3>

</div>
</header>
<div class="navbar">
<ul>
<li><a href="Home.jsp">Home</a></li>
<li><a href="candidateregister.jsp">Add Candidate</a></li>
<li><a href="display.jsp">Manage Candidate</a></li>
<li><a href="AddElection.jsp">Add Election</a></li>
<li><a href="adminresult.jsp">Result</a></li>

<li><a href="logout.jsp">Logout</a></li>
</ul>
</div>

51
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Code:-
 Home.jsp:-

<%--
Document : Home
Created on : 19 Jan, 2023, 2:40:26 PM
Author : khadk
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ADMIN PAGE</title>
<link rel='stylesheet'
href='home.css'
type='text/css'
media='all'>
</head>
<body>
<%
if(session.getAttribute("uname")==null)
{
response.sendRedirect("input.html");
}
%>
<header class="site-header">
<div class="site-identity">
<a href="#"><img src="images/logo.png" alt="Site Name" width="140px"
height="70px"/></a>
<h1 style="color:white;"><a href="#">Online Voting System</a></h1>
</div>
<div class="nav-header">

<img src="images/adminlogo.jpg" alt="Site Name" width="50px"


height="50px"/>
<h3> <%=session.getAttribute("uname")%> Panel</h3>

</div>
</header>
<div class="navbar">
<ul>
<li><a href="Home.jsp">Home</a></li>
<li><a href="candidateregister.jsp">Add Candidate</a></li>
<li><a href="display.jsp">Manage Candidate</a></li>

52
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

<li><a href="AddElection.jsp">Add Election</a></li>


<li><a href="adminresult.jsp">Result</a></li>
<li><a href="logout.jsp">Logout</a></li>
</ul>
</div>

<div class="container">
<img src="images/Election_Header.jpg" alt="Site Name" width="1515px"
height="600px"/>
<button class="btn">Get Started</button>
<div class="top-left">Online <br> VOTE</div>
<div class="top-middle">User can give his\her vote online <br> with out going to
any polling booth.</div>
<div class="hompage"><h2>Why Choose Us?</h2></div><div class="hompage-
cont"><span>This website is the best eVoting software due to following
reasons</span></div>
<br><div class="row">
<div class="column">
<img class="" src="https://dymk4s89vutua.cloudfront.net/wp-
content/plugins/r2v-api/images/icons/secured.png?x41032" width="50px"
height="50px" alt="100% Secure">
<h3>100% Secure</h3>
<p>
Right2Vote's online voting system has many layers of security
making the platform <span>100% secure.</span>
Security features include encryption, authentication based on Biometric.
</p>
</div>

<div class="column">
<img class="" src="https://dymk4s89vutua.cloudfront.net/wp-
content/plugins/r2v-api/images/icons/secured.png?x41032" width="50px"
height="50px" alt="100% Secure">
<h3>100% Secure</h3>
<p>
Right2Vote's online voting system has many layers of security
making the platform <span>100% secure.</span>
Security features include encryption, authentication based on Biometric.
</p>
</div>
<div class="column">
<img class="" src="https://dymk4s89vutua.cloudfront.net/wp-
content/plugins/r2v-api/images/icons/secured.png?x41032" width="50px"
height="50px" alt="100% Secure">
<h3>100% Secure</h3>
<p>

53
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Right2Vote's online voting system has many layers of security


making the platform <span>100% secure.</span>
Security features include encryption, authentication based on Biometric.
</p>
</div>
</div>
<br>

<%@ include file="footer.jsp" %>


</body>
</html>

54
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Add Candidate

 Component Table

Sr .No Component Component Name Code value


1 Label Full Name txtname
2 Label Email txtemail
3 Label DOB txtdob
4 Label Address txtaadr
5 Label Contact txtcon
6 Label Upload txtfile
7 Label Gender gender
8 Label Contact txtcon
9 Label File txtfile
10 Label Gender gender
11 Button Register popUpYes
12 Button Cancel popUpYes

Candidatestore.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mypack;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

55
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

import javax.servlet.http.Part;

/**
*
* @author khadk
*/
@WebServlet(name="candidatestore" ,urlPatterns={"/candidatestore"})
@MultipartConfig(maxFileSize=16177216)
public class candidatestore extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

Part part=request.getPart("txtfile");
String fname=request.getParameter("txtname");
String email=request.getParameter("txtemail");
String dob=request.getParameter("txtdob");
String aadr=request.getParameter("txtaddr");
String cont=request.getParameter("txtcon");
String gend=request.getParameter("gender");
if(part!=null) {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con
=DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");
PreparedStatement pst=con.prepareStatement("insert into CANDIDATE
values(DEFAULT,?,?,?,?,?,?,?)");
InputStream is=part.getInputStream();
pst.setString(1,fname);
pst.setString(2,email);
pst.setString(3,dob);
pst.setString(4,aadr);
pst.setString(5,cont);
pst.setBlob(6,is);
pst.setString(7,gend);
int i=pst.executeUpdate();
if(i>0)
out.println("<script type=\"text/javascript\">");
out.println("alert('You are successfully registered...');");
out.println("</script>");

56
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

RequestDispatcher rd=request.getRequestDispatcher("candidateregister.jsp");
rd.include(request, response);
pst.close();
con.close();
}
catch(Exception e)
{
out.println(e);
}

}
}
}

57
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Code For ManageCandidate:-

DbConnection.java

package com.pst.ir.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DbConnection {


static Connection con=null;
public static Connection getConnection()
{
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","
VOTING","VOTING");
}catch(Exception e) {
System.out.println(e);
}
return con;
}
}

ImageDto.java

package com.pst.ir.dto;

public class ImageDto {


private String id;
private String name,email,date,addr,contact,gender;

public String getId() {


return id;
}

public void setId(String id) {


this.id = id;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}
58
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

public String getEmail() {


return email;
}

public void setEmail(String email) {


this.email = email;
}

public String getDate() {


return date;
}

public void setDate(String date) {


this.date = date;
}

public String getAddr() {


return addr;
}

public void setAddr(String addr) {


this.addr = addr;
}

public String getContact() {


return contact;
}

public void setContact(String contact) {


this.contact = contact;
}

public String getGender() {


return gender;
}

public void setGender(String gender) {


this.gender = gender;
}

59
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

ImageDao.java

package com.pst.ir.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.pst.ir.dto.ImageDto;
import com.pst.ir.util.DbConnection;

public class ImageDao {


private final String GET_DATA = "select NID,NAME,CONTACT from
CANDIDATE";
private final String GET_IMAGE_QUERY = "select FILE from CANDIDATE where
NID=?";
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;

public List<ImageDto> getData(){


ImageDto imageDto = null;
List<ImageDto> imageList = new ArrayList<ImageDto>();
try {
con = DbConnection.getConnection();
ps = con.prepareStatement(GET_DATA);
rs = ps.executeQuery();
while(rs.next()) {
imageDto = new ImageDto();
imageDto.setId(rs.getString(1));
imageDto.setName(rs.getString(2));
imageDto.setContact(rs.getString(3));
imageList.add(imageDto);
}
}catch(Exception e) {

e.printStackTrace();
}
finally{
try{
rs.close();
ps.close();
}
catch(Exception e){

60
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

e.printStackTrace();
}
}

return imageList;
}

public byte[] getImage(String id){


byte[] image = null;
try {
con = DbConnection.getConnection();
ps = con.prepareStatement(GET_IMAGE_QUERY);
ps.setString(1, id);
rs = ps.executeQuery();
if(rs.next()) {
image = rs.getBytes(1);
}
}catch(Exception e) {
e.printStackTrace();
}
finally{
try{
rs.close();
ps.close();
}
catch(Exception e){

e.printStackTrace();
}
}

return image;
}
}

ImageDownloader.java

package

com.pst.ir.downloader; import

java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
61
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

import javax.servlet.annotation.WebServlet;

62
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pst.ir.dao.ImageDao;

@WebServlet("/ImageDownloader")
public class ImageDownloader extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
ImageDao dao = null;
ServletOutputStream outputStream = null;
String id = req.getParameter("id");
dao = new ImageDao();
byte[] image = dao.getImage(id);
outputStream = resp.getOutputStream();
outputStream.write(image);
outputStream.close();
}
}

ImageViewerController.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.pst.ir.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
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 com.pst.ir.dao.ImageDao;
import com.pst.ir.dto.ImageDto;

63
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

@WebServlet("/ImageViewerController")
public class ImageViewerController extends HttpServlet {
private static final long serialVersionUID = 1L;

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ImageDao imageDao = null;
imageDao = new ImageDao();
List<ImageDto> list = imageDao.getData();
req.setAttribute("list", list);
RequestDispatcher dispatcher = req.getRequestDispatcher("image.jsp");
dispatcher.forward(req, resp);

}
}

Image.jsp

<%@page import="java.util.ArrayList"%>
<%@page import="com.pst.ir.dto.ImageDto"%>
<%@page import="java.util.List"%>
<%@ page import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Image</title>
<style>
#candidate th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #0047AB;
color: white;
}
#candidate {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

64
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

#candidate td, #candidate th {


border: 1px solid #ddd;
padding: 8px;
}

</style>
</head>
<body>

<center>
<%
List<ImageDto> list = (ArrayList<ImageDto>)request.getAttribute("list");
%>

<table border="1px" width="1000px;" id="candidate">


<thead>
<tr><th>ID</th><th>NAME</th><th>CONTACT</th><th>IMAGE</th><th>EDIT
</th><th>DELETE</th></tr>
</thead>
<%
for(int i=0;i<list.size();i++){
ImageDto dto = list.get(i);
String id = dto.getId();
String name = dto.getName();
String contact = dto.getContact();
%>
<tr><td><%=id%></td><td style="width: 350px;"><%=name
%></td><td><%=contact%></td><td style="width: 150px;height: 120px"><img
src="./ImageDownloader?id=<%=id%>" height="120" width="150px"/></td><td><a
href="UpdateCandidate.jsp?id=<%=id%>" target="blank">Edit</a></td><td><a
href="./DeleteServlet?id=<%=id%>">Delete</a></td></tr>
<%}
%>

</table>
</center>

</body>
</html>

65
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 Add Election

 Component Table

Sr .No Component Component Name Code Value


1 Label Election Topic ename
2 Select Id cid
3 Select Name name
4 Label End Date edate
5 Button Register submit
6 Button Cancel reset

Electionstore.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mypack;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

/**
*
* @author khadk
*/
@WebServlet(name="electionstore" ,urlPatterns={"/electionstore"})
@MultipartConfig(maxFileSize=16177216)

66
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

public class electionstore extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

int cid=Integer.parseInt(request.getParameter("cid"));
String ename=request.getParameter("ename");
String name=request.getParameter("name");
String edate=request.getParameter("edate");

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con
=DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");
PreparedStatement stmt = con.prepareStatement("SELECT * FROM candidate
WHERE NID=?");
stmt.setInt(1, cid);
ResultSet rs = stmt.executeQuery();

// Retrieve the candidate's ID and other details from the candidate table
if (rs.next()) {
String email=rs.getString("EMAIL");
String date = rs.getString("DATE");
byte[] photoBytes = rs.getBytes("File");
String gend=rs.getString("GENDER") ;

// and other details you want to retrieve


PreparedStatement stmt2 = con.prepareStatement("INSERT INTO election (EID,
ENAME,CID, NAME,EMAIL, DATE, FILE,GENDER,EDATE, VOTE) VALUES
(DEFAULT, ?,?,?, ?, ?,?,?, ?, DEFAULT)");

stmt2.setString(1, ename);
stmt2.setInt(2,cid);
stmt2.setString(3, name);
stmt2.setString(4,email);
stmt2.setString(5, date);
stmt2.setBytes(6, photoBytes);
stmt2.setString(7, gend);
stmt2.setString(8, edate);

67
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

// and other candidate details you want to insert


stmt2.executeUpdate();

} out.println("<script type=\"text/javascript\">");
out.println("alert('Successfully Generated...');");
out.println("</script>");
RequestDispatcher rd=request.getRequestDispatcher("AddElection.jsp");
rd.include(request, response);

con.close();
}
catch(Exception e)
{
out.println(e);
}

}
}

68
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Code:
AdminResult.jsp:

<%--
Document : adminresult
Created on : 7 Apr, 2023, 11:00:09 AM
Author : khadk
--%>

<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Base64"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="java.io.ByteArrayInputStream"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
.cards{
width:20%;

border-radius:5px;
margin:40px;
box-shadow:2px 2px 10px black;
}

.image img{
width:100%;
border-top-right-radius5px;
border-top-left-radius:5px;
}
.title{
text-align: center;
padding:0x;
font-weight: 600;

69
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

font-family:Helvetica, sans-serif ;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
text-align: center;
}

.form {
display: flex;
justify-content: center;
align-items: center;
}

.select {
margin-right: 10px;
}

button {
margin-right: 10px;
margin-top: 1px;
margin-left: 5px;
}

.elec {
font-size: 20px;
color: #0437F2;
font-family: Helvetica, sans-serif;
font-weight: 500;
}

select {
color: black;
font-size: inherit;
padding: .5em;
padding-right: 2.5em;
border: 0;
margin: 0;
border:1px solid black;
width:70%;
border-radius: 3px;
text-indent: 0.01px;
text-overflow: '';
-webkit-appearance: button; /* hide default arrow in chrome OSX */

70
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

input[type=submit]{
width:150px;
margin-top:0px;
padding:8px;

font-size:17px;
color:#fff;
border:none;
font-family:Helvetica, sans-serif;

border-radius:5px;
background-color:#0437F2;

}
#popUpYes:hover {
background-color: orange;
}
form {
display: flex;
align-items: center;
}

select {
flex: 1;
}

input[type="submit"]
{ margin-left: 10px;
}
#candidate th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #0047AB;
color: white;
}
#candidate {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#candidate td, #candidate th {


border: 1px solid #ddd;

71
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

padding: 8px;
}

</style>
</head>
<body>
<%@ include file="adminhead.jsp" %>
<br><br>
<%
// Connect to the database
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");

// Query the database for the available election topics


PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT ename
FROM election");
ResultSet rs = stmt.executeQuery();

// Build a list of election topics


List<String> electionTopics = new ArrayList<String>();
while (rs.next()) {
String topic = rs.getString("ename");
electionTopics.add(topic);
}

// Check if a topic was selected from the form


String selectedTopic = request.getParameter("electionTopic");

// If a topic was selected, query the database for the candidates in that election
Map<Integer, String[]> candidateDetails = new HashMap<Integer, String[]>();
Date endDate = null; // Initialize endDate to null
if (selectedTopic != null && !selectedTopic.isEmpty()) {
PreparedStatement stmt2 = conn.prepareStatement("SELECT cid, name, vote, edate
FROM election WHERE ename = ?");
stmt2.setString(1, selectedTopic);
ResultSet rs2 = stmt2.executeQuery();

// Build a map of candidate IDs to candidate details (name and vote count)
while (rs2.next()) {
int cid = rs2.getInt("cid");
String candidateName = rs2.getString("name");
int voteCount = rs2.getInt("vote");
Date electionEndDate = rs2.getDate("edate"); // Fetch the end date from the
database

72
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

candidateDetails.put(cid, new String[] {candidateName,


Integer.toString(voteCount)});
if (endDate == null || electionEndDate.after(endDate)) {
endDate = electionEndDate;
}
}
}

%>

<div class="container">
<center><div class="elec">Select an election topic:-</div></center>
<form action="" method="get">
<label for="electionTopic"></label>
<select name="electionTopic" id="electionTopic">
<option value="">--Select a topic--</option>
<% for (String topic : electionTopics) { %>
<option value="<%= topic %>"><%= topic %></option>
<% } %>
</select>
<input type="submit" id="popUpYes" value="View Result">
</form>
</div>

<% if (endDate == null) { %>

<% } else if (endDate.after(new Date())) { %>


<p style="font-size:25px;background-color:blue;color:white;text-
align:center;">The results will be available after <%= endDate %>!!!!.</p>
<% } else if (!candidateDetails.isEmpty()) { %>
<center>
<br><br>
<table border="1px" width="400px" id="candidate">
<tr>
<th>Candidate ID</th>
<th>Candidate Name</th>
<th>Votes Received</th>
</tr>
<% for (Map.Entry<Integer, String[]> entry : candidateDetails.entrySet()) {
%>
<tr>
<td><%= entry.getKey() %></td>
<td><%= entry.getValue()[0] %></td>
<td><%= entry.getValue()[1] %></td>
</tr>
<% } %>

73
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

</table>
</center>
<% } else { %>
<p>No winner has been determined for the <%= selectedTopic %> election.</p>
<% } %>

<%
rs.close();
stmt.close();
conn.close();
%>

<%@ include file="footer.jsp" %>


</body>
</html>

74
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

 UserNavigation Page

 Component Table

Sr .No Component Component Name Code value


1 HyperLink Home -
2 HyperLink View Candidate -
3 HyperLink Result -
4 HyperLink View Profile -
5 HyperLink Logout -
6 HyperLink AboutUs -

USerhead.jsp

<%--
Document : userhead
Created on : 29 Mar, 2023, 11:08:05 AM
Author : khadk
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel='stylesheet'
href='userhome.css'
type='text/css'
media='all'>
</head>
<body>
<%
if(session.getAttribute("uname")==null)
{
response.sendRedirect("index.html");
}
%>
<header class="site-header">
<div class="site-identity">
<a href="#"><img src="images/logo.png" alt="Site Name" width="140px"
height="70px"/></a>
<h1 style="color:white;"><a href="#">Online Voting System</a></h1>

75
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

</div>
<div class="nav-header">

<img src="images/adminlogo.jpg" alt="Site Name" width="50px"


height="50px"/>
<h3> <%=session.getAttribute("uname")%> </h3>

</div>
</header>
<div class="navbar">
<ul>
<li><a href="userhome.jsp">Home</a></li>
<li><a href="voter.jsp">View Candidate</a></li>
<li><a href="result.jsp">Result</a></li>
<li><a href="viewprofile.jsp">View Profile</a></li>
<li><a href="userlogout.jsp">Logout</a></li>
<li><a href="logout.jsp">About Us</a></li>
</ul>
</div>

</body>
</html>

76
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Code:-
Voter(View Candidate).jsp:-

<%--
Document : voter
Created on : 29 Mar, 2023, 5:16:02 PM
Author : khadk
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<%@page import="java.util.Base64"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>

<style>
.elec{

font-size:20px;
color:#0437F2;
font-family:Helvetica, sans-serif;
font-weight:500;
}
select {

color: black;
font-size: inherit;
padding: .5em;
padding-right: 2.5em;
border: 0;
margin: 0;
border:1px solid black;
width:15%;
border-radius: 3px;
text-indent: 0.01px;
text-overflow: '';
-webkit-appearance: button; /* hide default arrow in chrome OSX */
}
input[type=submit]{
width:150px;
margin-top:0px;
padding:8px;

font-size:17px;

77
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

color:#fff;
border:none;
font-family:Helvetica, sans-serif;

border-radius:5px;
background-color:#0437F2;

}
#popUpYes:hover {
background-color: orange;
}
.cards{
width:20%;
display:inline-block;
border-radius:5px;
margin:40px;
box-shadow:2px 2px 10px black;
}

.image img{
width:100%;
border-top-right-radius5px;
border-top-left-radius:5px;
}
.title{
text-align: center;
padding:0x;
}
.des{
text-align:center;
padding:4px;
}
button{
margin-top:30px;
margin-bottom:30px;
background-color:white;
border:1px solid black;
padding:5px;
border-radius:5px;
cursor:pointer;
}
button:hover{
background-color:#0437F2;
color:white;
transition:.5s

78
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
text-align: center;
}

.form {
display: flex;
justify-content: center;
align-items: center;
}

.select {
margin-right: 10px;
}

.elec {
margin-right: 10px;
}

button {
margin-right:10px;
margin-top: 1px;
margin-left: 5px;
}
</style>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%@ include file="userhead.jsp" %>
<br><br><br>

<%

// Connect to the database


Connection conn =
DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");
// Retrieve the election topics from the database

79
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Statement stmt = conn.createStatement();


ResultSet rs = stmt.executeQuery("SELECT DISTINCT (ename), edate FROM
election");
out.println("<form method='post'>");
// Create a select tag for the election topics
out.println("<div class='container'>");
out.println(" <center> <div class='elec'>Election Topic:-</div></center>");
out.println("<select name='election_topic'>");
while (rs.next()) {
String fname = rs.getString("ename");
Date end_time = rs.getDate("edate");
if (end_time.after(new Date())) {
// Election has not ended yet, so display candidate information
out.println("<option value='" + fname + "'>" + fname + "</option>");
} else {
// Election has ended, so display message
out.println("<option value='' disabled>" + fname + " (Election
ended)</option>");
}
}
out.println("</select>");
// Add a submit button
out.println("&nbsp &nbsp<input type='submit' value='View Candidate'
id='popUpYes'>");
out.println("</form>");
out.println("</div>");

// If a topic has been selected, display candidate information


String username = (String) session.getAttribute("uname");

// Get the selected election topic from the form submission


String selectedTopic = request.getParameter("election_topic");

if (selectedTopic != null) {
// Check if the user has already voted for this topic
PreparedStatement ps = conn.prepareStatement("SELECT * FROM votes WHERE
USERNAME=? AND ENAME=?" );
ps.setString(1, username);
ps.setString(2, selectedTopic);

ResultSet rs1 = ps.executeQuery();

if (rs1.next()) {
// User has already voted, display an error message
out.println("<script type=\"text/javascript\">");
out.println("alert('You have already voted .');");

80
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

out.println("</script>");

} else {
// User has not voted yet, display the candidate information and a vote button
rs = stmt.executeQuery("SELECT cid,name, file, gender FROM election
WHERE ename='" + selectedTopic + "'");
while (rs.next()) {
int cid=rs.getInt("cid");
String cname = rs.getString("name");
Blob cphoto = rs.getBlob("file");
String cgender = rs.getString("gender");
byte[] cphotoBytes = cphoto.getBytes(1, (int) cphoto.length());
String cphotoBase64 = Base64.getEncoder().encodeToString(cphotoBytes);

// Display the candidate information and a vote button


out.println("<div class='cards'>");
out.println("<div class='image'>");
out.println("<img src='data:image/jpeg;base64, " + cphotoBase64 + "'
alt='Candidate Photo'>");
out.println("</div>");
out.println("<div class='title'>");
out.println("<br>Candidate Name:-" + cname +"<br><br>");
out.println("Candidate Id:-" + cid );
out.println("</div>");
out.println("<div class='des'>");
out.println("<p>Gender: " + cgender + "</p>");
out.println("<form method='post' action='vote-handler.jsp'>");
out.println("<input type='hidden' name='election_topic' value='" +
selectedTopic + "'>");
out.println("<input type='hidden' name='cid' value='" + cid + "'>");
out.println("<button type='submit'>VOTE</button>");
out.println("</form>");
out.println("</div>");
out.println("</div>");
}
}
}
%>

<%@ include file="footer.jsp" %>


</body>
</html>

81
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Code:-
Result.jsp:-

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Base64"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="java.io.ByteArrayInputStream"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>

<html>
<head>
<style>
.cards{
width:20%;

border-radius:5px;
margin:40px;
box-shadow:2px 2px 10px black;
}

.image img{
width:100%;
border-top-right-radius5px;
border-top-left-radius:5px;
}
.title{
text-align: center;
padding:0x;
font-weight: 600;
font-family:Helvetica, sans-serif ;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
text-align: center;
}

.form {

82
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

display: flex;
justify-content: center;
align-items: center;
}

.select {
margin-right: 10px;
}

button {
margin-right: 10px;
margin-top: 1px;
margin-left: 5px;
}

.elec {
font-size: 20px;
color: #0437F2;
font-family: Helvetica, sans-serif;
font-weight: 500;
}

select {
color: black;
font-size: inherit;
padding: .5em;
padding-right: 2.5em;
border: 0;
margin: 0;
border:1px solid black;
width:70%;
border-radius: 3px;
text-indent: 0.01px;
text-overflow: '';
-webkit-appearance: button; /* hide default arrow in chrome OSX */
}

input[type=submit]{
width:150px;
margin-top:0px;
padding:8px;

font-size:17px;
color:#fff;
border:none;
font-family:Helvetica, sans-serif;

83
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

border-radius:5px;
background-color:#0437F2;

}
#popUpYes:hover {
background-color: orange;
}
form {
display: flex;
align-items: center;
}

select {
flex: 1;
}

input[type="submit"]
{ margin-left: 10px;
}
</style>
</head>
<%@ include file="userhead.jsp" %>
<br><br>
<%
// Connect to the database
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");

// Query the database for the available election topics


PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT
ename FROM election");
ResultSet rs = stmt.executeQuery();

// Build a list of election topics


List<String> electionTopics = new ArrayList<String>();
while (rs.next()) {
String topic = rs.getString("ename");
electionTopics.add(topic);
}

// Check if a topic was selected from the form


String selectedTopic = request.getParameter("electionTopic");

84
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

// If a topic was selected, query the database for the candidates in that election
String winnerName = "";
String winnergender="";
int winnerVoteCount = 0;
byte[] winnerPhoto = null;
Date endDate = null; // Initialize endDate to null
if (selectedTopic != null && !selectedTopic.isEmpty()) {
PreparedStatement stmt2 = conn.prepareStatement("SELECT name,gender, file,
vote, edate FROM election WHERE ename = ?");
stmt2.setString(1, selectedTopic);
ResultSet rs2 = stmt2.executeQuery();

// Calculate the total votes for each candidate and determine the winner
int maxVotes = 0;
while (rs2.next()) {
String candidateName = rs2.getString("name");
String candidategender=rs2.getString("gender");
byte[] candidatePhoto = rs2.getBytes("file");
int voteCount = rs2.getInt("vote");
Date electionEndDate = rs2.getDate("edate"); // Fetch the end date from the
database
if (voteCount > maxVotes) {
maxVotes = voteCount;
winnerName = candidateName;
winnerPhoto = candidatePhoto;
winnergender= candidategender;
winnerVoteCount = voteCount;
}
if (endDate == null || electionEndDate.after(endDate)) {
endDate = electionEndDate;
}
}
}
%>

<div class="container">
<center><div class="elec">Select an election topic:</div></center>
<form action="" method="get">
<label for="electionTopic"></label>
<select name="electionTopic" id="electionTopic">
<option value="">--Select a topic--</option>
<% for (String topic : electionTopics) { %>
<option value="<%= topic %>"><%= topic %></option>
<% } %>
</select>
<input type="submit" id="popUpYes" value="View Result">

85
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

</form>
</div>

</html>
<% if (endDate == null) { %>

<% } else if (endDate.after(new Date())) { %>


<p style="font-size:25px;background-color:blue;color:white;text-align:center;">The
results will be available after <%= endDate %>!!!!.</p>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<%@ include file="footer.jsp" %>
<% } else if (!winnerName.isEmpty()) { %>
<center><p style="font-size:23px;background-color:blue;color:white;text-
align:center;">The Winner of the <%= selectedTopic %>!!!!!!</p>
<div class="cards"><div class="image"><img src='data:image/png;base64,<%=
Base64.getEncoder().encodeToString(winnerPhoto) %>'/></div>
<div class="title"> <br><%= winnerName %><br><br><%= winnergender
%></div>
</div></center>
<!-- display the vote
<% } else { %>

<p>No winner has been determined for the <%= selectedTopic %> election.</p>
<% } %>
<%

rs.close();
stmt.close();
conn.close();
%>

86
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Code:-
Aboutus.jsp:-

<%--
Document : Aboutus
Created on : 14 Apr, 2023, 6:12:46 AM
Author : khadk
--%>

<!DOCTYPE html>
<html>
<head>
<title>About Us</title>
</head>
<body>

<%@ include file="adminhead.jsp" %>


<h1>About Us</h1>
<p>Welcome to our online voting system! Our goal is to provide a simple
and secure way for people to vote online.</p>

<h2>Our Team</h2>
<ul>
<li>Maanbahadur khadka -Web Desinger</li>

</ul>

<h2>Contact Us</h2>
<p>If you have any questions or feedback about our system, please feel free
to contact us:</p>
<ul>
<li>Email: khadkamaanbahadur15@gmail.com</li>
<li>Phone: 555-1234</li>
<li>Address: 123 Main St, Anytown USA</li>
</ul>

<%@ include file="footer.jsp" %>


</body>
</html>

87
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

5.3.1 UNIT TESTING :

UNIT TESTING: It is a level of software testing where individual units/


components of a software are tested. The purpose is to validate that each unit
of the software performs as designed. A unit is the smallest testable part of
any software. It usually has one or a few inputs and usually a single output.
In procedural programming, a unit may be an individual program, function,
procedure, etc. In object-oriented programming, the smallest unit is a
method, which may belong to a base/ super class, abstract class or derived/
child class. (Some treat a module of an application as a unit. This is to be
discouraged as there will probably be many individual units within that
module.) Unit testing frameworks, drivers, stubs, and mock/ fake objects are
used to assist in unit testing.

Acceptance Testing
System Testing
Integration Testing
Unit Testing

88
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

5.3.1 INTEGRATION TESTING:

INTEGRATION TESTING: is a level of software testing where individual


units arecombined and tested as a group. The purpose of this level of testing
is to expose faults in the interaction between integrated units. Test drivers and
test stubs are used to assist in Integration Testing. Bottom-up testing is an
approach to integrated testing where the lowest level components are sted
first, then used to facilitate the testing of higher level components. The
processis repeated until the component at the top of the hierarchy is tested.
All the bottom or low-level modules, procedures or functions are integrated
and then tested. After the integration testing of Lower level integrated
modules, the next level of modules will be formed and can be used for
integration testing.
This approach is helpful only when all or most of the modules of the same
development level are ready. This method also helps to determine the levels
ofSoftware developed and makes it easier to report testing progress in the
form of a percentage.

Acceptance Testing
System Testing

Integration Testing

Unit Testing

89
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

BETA TESTING :

Beta Testing is one of the Customer Validation methodologies to evaluate


the level of customer satisfaction with the product by letting it to be
validated by the end users, who actually use it, for over a period of
time.Product experiencegained by the end users are asked for feedback on
design, functionality, and usability and this helps in assessing the quality of
the product. Real People, Real Environment, Real Product are the three R's
of Beta Testing and the question that arises here in Beta Testing is "Do
Customers like the Product?”.

 A beta test is the second phase of software testing in which a sampling


of the intended audience tries the product out. (Beta is the second
letter of the Greek alphabet.) Originally, the term alpha testing meant
the firstphase of testing in a software development process. The first
phase includes unit testing, component testing, and system testing.
Beta testing can be considered "pre-release testing.

 The goal of beta testing is to place your application in the hands of


realusers outside of your own engineering team to discover any
flaws or issues from the user's perspective that you would not
want to have in your final, released version of the application.
Example: Microsoft and many other organizations release beta
versions of their products to betested by users.

90
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

5.3.4 Test Cases

Sr. Form Name Test Case Test Data State Test Input Exp.
No Value Result
1 Admin Username Alphabetic Valid Admin12 Allowed
Login and Number to enter
data
Null Invalid Error
Message
Password Alphabetic, Valid Abc@1234 Allowed
Number, to enter
Symbol data
Null Invalid Error
Message
2 Voter VoterId Alphabetic valid Maan12 Allowed
Register and to enter
Number data
Number Invalid 12345 Error
Message
Special Invalid !@#$%^&*()- Error
Symbol +?;:”’~ Message
Name Alphabetic valid Maan Allow
to enter
data
Number invalid 4151 Error
Message
Special !@#$%^&*()- Error
Symbol +?;:”’~ Message
Username Alphabetic Valid Maan12 Allowed
and Number to enter
data
Null Invalid Error
Message
Password Alphabetic, Valid Abc@1234 Allowed
Number, to enter
Symbol data
Null Invalid Error
Message

91
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Email-ID Alphabetic, Valid abc@gmail.com Allowed


Number, @ to enter
and , Symbol data
Null Invalid Error
Message
Password Alphabetic, Valid Abc@1234 Allowed
Number, to enter
Symbol data
DOB DD-MM-YYYY Valid 15-2-2002 Allowed
format to enter
data
Null Invalid Error
Message
Alphabet Invalid 15a@ Error
and symbol Message
DOB<18 Valid 1/2/2002 Allowed
to
enter
data
Address Alphabetic, Valid Room no/10 Allowed
Number, to enter
Symbol data
Null Invalid Error
Message
Contact Number Valid 7894561232 Allowed
to enter
data
Alphabet Invalid huab@@ Error
and Symbol Message
Photo .jpg,.png valid Maan.jpg Allowed
to enter
data
.pdf,doc Invalid Maan.pdf Error
other Message
format file
Fingerprint Ansi format Valid text Allowed
to enter
data
Null Invalid Allowed
to enter
data

92
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

3 Add Name Alphabetic valid Rahul Allow


Candiate to enter
data
Number invalid 4151 Error
Message
Special !@#$%^&*()- Error
Symbol +?;:”’~ Message
Email-ID Alphabetic, Valid rah@gmail.com Allowed
Number, @ to enter
and , Symbol data
Null Invalid Error
Message
DOB DD-MM-YYYY Valid 15-2-2002 Allowed
format to enter
data
Null Invalid Error
Message
Alphabet Invalid 15a@ Error
and symbol Message
Address Alphabetic, Valid Room no/1 Allowed
Number, to enter
Symbol data
Null Invalid Error
Message
Contact Number Valid 7894561532 Allowed
to enter
data
Alphabet Invalid huab@@ Error
and Symbol Message
Photo .jpg,.png valid n.jpg Allowed
to enter
data
.pdf,doc Invalid n.pdf Error
other Message
format file
4 Add Election Topic Alphabetic valid Election Allow
to enter
data
Number invalid 4151 Error
Message

93
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Special !@#$%^&*()- Error


Symbol +?;:”’~ Message
Id Number valid 1 Allow to
enter data
Null Invalid Error
Message
Name Alphabetic valid Maan Allow
to enter
data
Number invalid 4151 Error
Message
Special !@#$%^&*()- Error
Symbol +?;:”’~ Message
EndDate DD-MM-YYYY Valid 15-04-2023 Allowed
format to enter
data
Null Invalid Error
Message
Alphabet Invalid 15a@ Error
and symbol Message

94
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

95
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Test

Report

1)Admin

:- Result

Code:-

Adminresult.jsp

<%--
Document : adminresult
Created on : 7 Apr, 2023, 11:00:09 AM
Author : khadk
--%>

<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Base64"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="java.io.ByteArrayInputStream"%>
96
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

<%@ page import="java.sql.*" %>

97
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

<%@ page import="java.util.Date" %>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
.cards{
width:20%;

border-radius:5px;
margin:40px;
box-shadow:2px 2px 10px black;
}

.image img{
width:100%;
border-top-right-radius5px;
border-top-left-radius:5px;
}
.title{
text-align: center;
padding:0x;
font-weight: 600;
font-family:Helvetica, sans-serif ;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
text-align: center;
}

.form {
display: flex;
justify-content: center;
align-items: center;
}

.select {
margin-right: 10px;
}

98
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

button {
margin-right: 10px;
margin-top: 1px;
margin-left: 5px;
}

.elec {
font-size: 20px;
color: #0437F2;
font-family: Helvetica, sans-serif;
font-weight: 500;
}

select {
color: black;
font-size: inherit;
padding: .5em;
padding-right: 2.5em;
border: 0;
margin: 0;
border:1px solid black;
width:70%;
border-radius: 3px;
text-indent: 0.01px;
text-overflow: '';
-webkit-appearance: button; /* hide default arrow in chrome OSX */
}

input[type=submit]{
width:150px;
margin-top:0px;
padding:8px;

font-size:17px;
color:#fff;
border:none;
font-family:Helvetica, sans-serif;

border-radius:5px;
background-color:#0437F2;

}
#popUpYes:hover {
background-color: orange;
}

99
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

form {
display: flex;
align-items: center;
}

select {
flex: 1;
}

input[type="submit"]
{ margin-left: 10px;
}
#candidate th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #0047AB;
color: white;
}
#candidate {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#candidate td, #candidate th {


border: 1px solid #ddd;
padding: 8px;
}

</style>
</head>
<body>
<%@ include file="adminhead.jsp" %>
<br><br>
<%
// Connect to the database
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");

// Query the database for the available election topics


PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT ename
FROM election");
ResultSet rs = stmt.executeQuery();

100
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

// Build a list of election topics


List<String> electionTopics = new ArrayList<String>();
while (rs.next()) {
String topic = rs.getString("ename");
electionTopics.add(topic);
}

// Check if a topic was selected from the form


String selectedTopic = request.getParameter("electionTopic");

// If a topic was selected, query the database for the candidates in that election
Map<Integer, String[]> candidateDetails = new HashMap<Integer, String[]>();
Date endDate = null; // Initialize endDate to null
if (selectedTopic != null && !selectedTopic.isEmpty()) {
PreparedStatement stmt2 = conn.prepareStatement("SELECT cid, name, vote, edate
FROM election WHERE ename = ?");
stmt2.setString(1, selectedTopic);
ResultSet rs2 = stmt2.executeQuery();

// Build a map of candidate IDs to candidate details (name and vote count)
while (rs2.next()) {
int cid = rs2.getInt("cid");
String candidateName = rs2.getString("name");
int voteCount = rs2.getInt("vote");
Date electionEndDate = rs2.getDate("edate"); // Fetch the end date from the
database
candidateDetails.put(cid, new String[] {candidateName,
Integer.toString(voteCount)});
if (endDate == null || electionEndDate.after(endDate)) {
endDate = electionEndDate;
}
}
}

%>

<div class="container">
<center><div class="elec">Select an election topic:-</div></center>
<form action="" method="get">
<label for="electionTopic"></label>
<select name="electionTopic" id="electionTopic">
<option value="">--Select a topic--</option>
<% for (String topic : electionTopics) { %>
<option value="<%= topic %>"><%= topic %></option>
<% } %>

101
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

</select>
<input type="submit" id="popUpYes" value="View Result">
</form>
</div>

<% if (endDate == null) { %>

<% } else if (endDate.after(new Date())) { %>


<p style="font-size:25px;background-color:blue;color:white;text-
align:center;">The results will be available after <%= endDate %>!!!!.</p>
<% } else if (!candidateDetails.isEmpty()) { %>
<center>
<br><br>
<table border="1px" width="400px" id="candidate">
<tr>
<th>Candidate ID</th>
<th>Candidate Name</th>
<th>Votes Received</th>
</tr>
<% for (Map.Entry<Integer, String[]> entry : candidateDetails.entrySet()) {
%>
<tr>
<td><%= entry.getKey() %></td>
<td><%= entry.getValue()[0] %></td>
<td><%= entry.getValue()[1] %></td>
</tr>
<% } %>
</table>
</center>
<% } else { %>
<p>No winner has been determined for the <%= selectedTopic %> election.</p>
<% } %>

<%
rs.close();
stmt.close();
conn.close();
%>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<%@ include file="footer.jsp" %>
</body>
</html>

102
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

2) User :-

Result
-

Code:-

Result.jsp

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Base64"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="java.io.ByteArrayInputStream"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>

<html>
<head>
<style>
.cards{
width:20%;

103
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

border-radius:5px;
margin:40px;
box-shadow:2px 2px 10px black;
}

.image img{
width:100%;
border-top-right-radius5px;
border-top-left-radius:5px;
}
.title{
text-align: center;
padding:0x;
font-weight: 600;
font-family:Helvetica, sans-serif ;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
text-align: center;
}

.form {
display: flex;
justify-content: center;
align-items: center;
}

.select {
margin-right: 10px;
}

button {
margin-right: 10px;
margin-top: 1px;
margin-left: 5px;
}

.elec {
font-size: 20px;
color: #0437F2;
font-family: Helvetica, sans-serif;
font-weight: 500;

104
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

select {
color: black;
font-size: inherit;
padding: .5em;
padding-right: 2.5em;
border: 0;
margin: 0;
border:1px solid black;
width:70%;
border-radius: 3px;
text-indent: 0.01px;
text-overflow: '';
-webkit-appearance: button; /* hide default arrow in chrome OSX */
}

input[type=submit]{
width:150px;
margin-top:0px;
padding:8px;

font-size:17px;
color:#fff;
border:none;
font-family:Helvetica, sans-serif;

border-radius:5px;
background-color:#0437F2;

}
#popUpYes:hover {
background-color: orange;
}
form {
display: flex;
align-items: center;
}

select {
flex: 1;
}

input[type="submit"]
{ margin-left: 10px;
}

105
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

</style>
</head>
<%@ include file="userhead.jsp" %>
<br><br>
<%
// Connect to the database
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:derby://localhost:1527/VOTING","VOTING","
VOTING");

// Query the database for the available election topics


PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT ename
FROM election");
ResultSet rs = stmt.executeQuery();

// Build a list of election topics


List<String> electionTopics = new ArrayList<String>();
while (rs.next()) {
String topic = rs.getString("ename");
electionTopics.add(topic);
}

// Check if a topic was selected from the form


String selectedTopic = request.getParameter("electionTopic");

// If a topic was selected, query the database for the candidates in that election
String winnerName = "";
String winnergender="";
int winnerVoteCount = 0;
byte[] winnerPhoto = null;
Date endDate = null; // Initialize endDate to null
if (selectedTopic != null && !selectedTopic.isEmpty()) {
PreparedStatement stmt2 = conn.prepareStatement("SELECT name,gender, file,
vote, edate FROM election WHERE ename = ?");
stmt2.setString(1, selectedTopic);
ResultSet rs2 = stmt2.executeQuery();

// Calculate the total votes for each candidate and determine the winner
int maxVotes = 0;
while (rs2.next()) {
String candidateName = rs2.getString("name");
String candidategender=rs2.getString("gender");
byte[] candidatePhoto = rs2.getBytes("file");
int voteCount = rs2.getInt("vote");
Date electionEndDate = rs2.getDate("edate"); // Fetch the end date from the

106
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

database
if (voteCount > maxVotes) {
maxVotes = voteCount;
winnerName = candidateName;
winnerPhoto = candidatePhoto;
winnergender= candidategender;
winnerVoteCount = voteCount;
}
if (endDate == null || electionEndDate.after(endDate)) {
endDate = electionEndDate;
}
}
}
%>

<div class="container">
<center><div class="elec">Select an election topic:</div></center>
<form action="" method="get">
<label for="electionTopic"></label>
<select name="electionTopic" id="electionTopic">
<option value="">--Select a topic--</option>
<% for (String topic : electionTopics) { %>
<option value="<%= topic %>"><%= topic %></option>
<% } %>
</select>
<input type="submit" id="popUpYes" value="View Result">
</form>
</div>

</html>
<% if (endDate == null) { %>

<% } else if (endDate.after(new Date())) { %>


<p style="font-size:25px;background-color:blue;color:white;text-align:center;">The
results will be available after <%= endDate %>!!!!.</p>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<%@ include file="footer.jsp" %>
<% } else if (!winnerName.isEmpty()) { %>
<center><p style="font-size:23px;background-color:blue;color:white;text-
align:center;">The Winner of the <%= selectedTopic %>!!!!!!</p>
<div class="cards"><div class="image"><img src='data:image/png;base64,<%=
Base64.getEncoder().encodeToString(winnerPhoto) %>'/></div>
<div class="title"> <br><%= winnerName %><br><br><%= winnergender
%></div>
</div></center>
<!-- display the vote

107
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

<% } else { %>

<p>No winner has been determined for the <%= selectedTopic %> election.</p>
<% } %>
<%

rs.close();
stmt.close();
conn.close();
%>

108
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

User Documentation

● How to get Login (Admin)?

1. Click on the Admin that will appear in the right side of the navigation bar.
2. After clicking it Admin login page will appear .
3. Fill the login Page
4. Click on Login Button
5. You will be Successfully Logged in.

 How to add Candidate?

1. Click on the Add Candidate link that will be in navigation bar.


2. After clicking the add candidate link Add Candidate form will appear
3. Fill the detail of the Candidate.
4. Click on Register Button now you have successfully added candidate

● How to generate Election?

1. Click on the Add Election link that will be in navigation bar


2. After Clicking it Add Election form will appear
3. Give Election Topic and select candidate id from select tag as well as candidate
name from select tag
4. Set End Date for Election
5. Now Click on register and then candidate will be added in Election

● How to see Result?

1. Click on the Result that will be in navigation bar


2. Now select election topic from select tag from which election you want to see
the result
3. Now a table will appear which will show which candidate get number of vote
in election

● How to get Logout?

1. Click on the Logout Link from navigation bar.

109
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

2. After clicking it will automatically redirect the admin to login page after 3
seconds.

● How to get Register ?

1. Click on the Voter link that will be in right side of navigation bar
2. After clicking it login form will open in login form one hyperlink will present
name as Click to “Register Here!” click on that.
3. After Clicking it register form will appear
4. Fill the details.
5. Click on register button
6. Success Register Alert box will appear now are register
successfully.

● How to login as Voter?

1. Click on the Vote link from navigation bar


2. After clicking it voter login page will appear if you have already register then
fill the login page or you are new you can follow the above step how to
register.
3. Click on the Login Button.
4. Now you will redirect to voter home page

● How to view Candidate?

1. Click on the view Candidate link from navigation bar.


2. After clicking it view candidate page will appear
3. To view the candidate select the election topic from select tag and click on the
view candidate button.
4. Now you can view the candidate successfully.

● How to see result as Voter?

1. After voter login one home page will appear in that navigation bar
result link will appear click on that.

110
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

2. After clicking the result link page will appear select the election topic from
which election you wan to see result and then click on the result button
3. After clicking it result will be appear in form of candidate name
and photo who have won the particular election.

● How to Get In Touch with us?

1. Click on the Aboutus link from navigation bar


2. You will get detail of project and below the detail there will be a gmail icon
3. After clicking on that icon you can send any query related to
website from gmail account.

111
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

112
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

CHAPTER 7 : CONCLUSIONS

Conclusion

An online voting system can provide a convenient and efficient way for people to cast
their votes from the comfort of their homes or workplaces, without the need to
physically go to a polling station. However, there are also several considerations and
potential drawbacks that should be taken into account.

One advantage of an online voting system is that it can increase voter participation, as
it eliminates barriers such as physical distance or mobility issues. It can also reduce
the costs and resources associated with traditional polling stations and paper-based
ballots. Additionally, an online voting system can provide a more efficient and
accurate vote counting process, with results available in real-time.

However, there are also concerns related to the security and integrity of an online
voting system. Hackers and other malicious actors may attempt to interfere with the
system, potentially compromising the confidentiality and accuracy of the votes.
Ensuring the security of the system and protecting against cyber attacks is therefore
crucial.

Another concern is the potential for technical issues or glitches, which could prevent
voters from accessing or using the system, or cause errors in vote counting. This could
undermine confidence in the system and lead to disputes or challenges to the results.

In conclusion, an online voting system has the potential to provide a convenient and
efficient way for people to cast their votes, but it is important to carefully consider and
address the security and technical challenges associated with such a system in order to
ensure its accuracy and legitimacy.

113
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Significance of the system

The significance of an online voting system lies in its potential to improve the
democratic process by making it more accessible, efficient, and accurate. By enabling
voters to cast their ballots from anywhere with an internet connection, an online
voting system can increase voter participation and reduce barriers to access for
individuals who may face physical or logistical challenges in getting to a physical
polling station.

Furthermore, an online voting system can also help reduce the costs and resources
associated with traditional polling stations, such as printing and distributing paper
ballots, staffing polling stations, and transporting and securing ballot boxes. This can
result in significant cost savings for governments and election commissions, which
can be redirected to other areas of public need.

Another significant advantage of an online voting system is its potential to improve


the accuracy and transparency of the vote counting process. With results available in
real-time and automated systems in place to check for inconsistencies or errors, an
online voting system can help reduce the risk of fraud or human error in the vote
counting process.

Overall, an online voting system has the potential to improve the integrity,
accessibility, and efficiency of the democratic process, and ensure that all eligible
citizens have the opportunity to participate in the democratic process.

114
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Limitations of the System

An online voting system also has several limitations and potential drawbacks that
must be considered before implementing such a system. Some of the key limitations
of an online voting system are:

1. Security concerns: One of the major limitations of an online voting system is


the potential for security breaches, which can compromise the confidentiality
and accuracy of the votes. Hackers or malicious actors may attempt to interfere
with the system, making it vulnerable to cyber attacks, malware, or other
malicious activities.

2. Accessibility: While an online voting system may increase access to voting for
some people, it may also limit access for others who do not have reliable
internet access or who may face technical difficulties in using the system.

3. Technical issues: Online voting systems may also be susceptible to technical


issues such as glitches, errors, or system crashes, which can prevent voters
from accessing or using the system, or cause errors in vote counting.

4. Voter authentication: It can be challenging to authenticate the identity of online


voters and prevent voter fraud, which could undermine the accuracy and
integrity of the voting process.

5. Trust and transparency: The lack of transparency in the online voting process
may also raise concerns about the fairness and legitimacy of the results, which
could undermine public trust in the democratic process.

In conclusion, an online voting system has several limitations and potential


drawbacks that must be carefully considered and addressed before implementing such
a system.
While it has the potential to increase accessibility, efficiency, and accuracy in the
democratic process, it is essential to ensure that the system is secure, reliable, and
transparent to maintain public trust and confidence in the voting process.

115
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

Future Scope of the Project

The future scope of an online voting system project is vast, as it has the potential to
transform the democratic process by making it more accessible, efficient, and
accurate. Some of the key areas for future development and improvement in an online
voting system project are:

1. Security: Developing robust security measures to prevent cyber attacks,


malware, or other malicious activities is critical to ensure the integrity and
confidentiality of the voting process.

2. Accessibility: Making the online voting system more accessible to a wider


range of voters, including those with disabilities, language barriers, or limited
access to technology, is important to ensure that all eligible voters have the
opportunity to participate in the democratic process.

3. User experience: Improving the user experience and usability of the online
voting system is essential to ensure that voters can easily navigate the system
and cast their votes without facing technical difficulties or errors.

4. Verification and auditability: Implementing verification and auditability


measures, such as paper trails or post-election audits, can increase transparency
and accountability in the voting process and help build public trust in the
system.

5. Integration with existing systems: Integrating the online voting system with
existing election infrastructure and systems, such as voter registration databases
or vote tabulation systems, can streamline the voting process and reduce the
potential for errors or discrepancies.

In conclusion, the future scope of an online voting system project is vast, and ongoing
development and improvement in security, accessibility, user experience, verification,
and integration with existing systems are critical to ensure the success and
effectiveness of such a system.

116
Name:-Students name here Roll No: 56
T.Y.B.Sc.IT Project title here

References:-

https://stackoverflow.com/questions/27825081/if-select-tag-option-is-selected-shows-
another-select-tag

https://www.tutorialspoint.com/index.htm

https://www.w3schools.com/

https://eci.gov.in/evm/

117
Name:-Students name here Roll No: 56

You might also like