diff --git a/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/DBUtilR.class b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/DBUtilR.class new file mode 100644 index 00000000..07670072 Binary files /dev/null and b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/DBUtilR.class differ diff --git a/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/againvote.class b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/againvote.class new file mode 100644 index 00000000..b3528019 Binary files /dev/null and b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/againvote.class differ diff --git a/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/loginpage.class b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/loginpage.class new file mode 100644 index 00000000..b46c3132 Binary files /dev/null and b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/loginpage.class differ diff --git a/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/registration.class b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/registration.class new file mode 100644 index 00000000..a64e8621 Binary files /dev/null and b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/registration.class differ diff --git a/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/thankyou.class b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/thankyou.class new file mode 100644 index 00000000..e2d3b57e Binary files /dev/null and b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/thankyou.class differ diff --git a/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/vote.class b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/vote.class new file mode 100644 index 00000000..a484556a Binary files /dev/null and b/Online Voting System/Online_Voting_System/build/classes/vote/com/servlet/vote.class differ diff --git a/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/DBUtilR.java b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/DBUtilR.java new file mode 100644 index 00000000..3e1e94ba --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/DBUtilR.java @@ -0,0 +1,30 @@ +package vote.com.servlet; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class DBUtilR { + static Connection conn = null; + static + { + try { + Class.forName("com.mysql.jdbc.Driver"); + + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/votingdb", "Vaishnavi", "Nelavetla@537"); + + if(!conn.isClosed()) { + System.out.println("Connection established"); + } + + } catch (ClassNotFoundException | SQLException e) { + System.out.println("Error in DBUtilFile"); + e.printStackTrace(); + } + } + + public static Connection getDBConnection() { + // TODO Auto-generated method stub + return conn; + } +} \ No newline at end of file diff --git a/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/againvote.java b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/againvote.java new file mode 100644 index 00000000..e5cf1b2f --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/againvote.java @@ -0,0 +1,18 @@ +package vote.com.servlet; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class againvote extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + doGet(request, response); + } + +} diff --git a/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/loginpage.java b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/loginpage.java new file mode 100644 index 00000000..aeb579ad --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/loginpage.java @@ -0,0 +1,71 @@ +package vote.com.servlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class loginpage extends HttpServlet { + private static final long serialVersionUID = 1L; + + final static Connection con=DBUtilR.getDBConnection(); + static PreparedStatement ps = null; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + PrintWriter out = response.getWriter(); + String card=request.getParameter("cardno"); + Integer pin=Integer.parseInt(request.getParameter("pin")); + + try { + if(check(card,pin)) + { + out.print("Successful Login...You Can Vote Now"); + RequestDispatcher rd=request.getRequestDispatcher("vote.html"); + rd.include(request,response); + } + else { + out.print("Sorry username or password error , Make new account"); + RequestDispatcher rd=request.getRequestDispatcher("registration.html"); + rd.include(request,response); + } + } + catch (SQLException e) { + e.printStackTrace(); + } + + + } + static boolean check(String card,Integer pin) throws SQLException + { + boolean r=false; + ps=con.prepareStatement("Select * from register where cardno=? and pin=?"); + ps.setString(1,card); + ps.setInt(2,pin); + ResultSet rs=ps.executeQuery(); + r=rs.next(); + + return r; + } + + static boolean checkvote(String card) throws SQLException + { + boolean r=false; + ps=con.prepareStatement("Select * from vote where cardno=?"); + ps.setString(1,card); + + ResultSet rs=ps.executeQuery(); + r=rs.next(); + + return r; + } + +} diff --git a/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/registration.java b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/registration.java new file mode 100644 index 00000000..43a43dfc --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/registration.java @@ -0,0 +1,75 @@ +package vote.com.servlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; + +public class registration extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + + String f=request.getParameter("fname"); + + String c=request.getParameter("cardno"); + String cn=request.getParameter("cono"); + String ad=request.getParameter("add"); + String dob=request.getParameter("dob"); + String email=request.getParameter("email"); + String pin=request.getParameter("pin"); + try + { + + Class.forName("com.mysql.jdbc.Driver"); + Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/votingdb","Vaishnavi","Nelavetla@537"); + PreparedStatement ps=con.prepareStatement("insert into register values(?,?,?,?,?,?,?)"); + ps.setString(1,f); + + ps.setString(2,c); + ps.setString(3,cn); + ps.setString(4,ad); + ps.setString(5,dob); + ps.setString(6,email); + ps.setString(7,pin); + int i=ps.executeUpdate(); + if(i>0) + { + out.print("Successfully your account has been created...PLEASE LOGIN"); + RequestDispatcher rd=request.getRequestDispatcher("loginpage.html"); + rd.include(request,response); + } + else + { + out.print("Failed account creation try again"); + RequestDispatcher rd=request.getRequestDispatcher("registration.html"); + rd.include(request,response); + } + + } + catch (Exception e2) { + out.print("Invalid , Failed account creation try again "+e2); + RequestDispatcher rd=request.getRequestDispatcher("registration.html"); + rd.include(request,response); + } + + out.close(); + +} + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + doPost(request, response); + } + +} diff --git a/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/thankyou.java b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/thankyou.java new file mode 100644 index 00000000..ab05b987 --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/thankyou.java @@ -0,0 +1,17 @@ +package vote.com.servlet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class thankyou extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + } + +} diff --git a/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/vote.java b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/vote.java new file mode 100644 index 00000000..4134f5c3 --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/java/vote/com/servlet/vote.java @@ -0,0 +1,97 @@ +package vote.com.servlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLIntegrityConstraintViolationException; + +public class vote extends HttpServlet { + private static final long serialVersionUID = 1L; + + final static Connection con=DBUtilR.getDBConnection(); + static PreparedStatement ps = null; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + + String f=request.getParameter("cardno"); + String l=request.getParameter("party"); + try + { + + Class.forName("com.mysql.jdbc.Driver"); + Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/votingdb","Vaishnavi","Nelavetla@537"); + + if(checkLogin(f)) + { + + ps=con.prepareStatement("insert into vote values(?,?)"); + ps.setString(1,f); + ps.setString(2,l); + int i=ps.executeUpdate(); + if(i>0) + { + out.print("Your Vote has been submitted successfully..."); + RequestDispatcher rd=request.getRequestDispatcher("thankyou.html"); + rd.include(request,response); + } + else + { + out.print("Failed to submit vote, try again"); + RequestDispatcher rd=request.getRequestDispatcher("vote.html"); + rd.include(request,response); + } + } + else + { + out.print("Please enter correct card number"); + RequestDispatcher rd=request.getRequestDispatcher("vote.html"); + rd.include(request,response); + } + } + catch (SQLIntegrityConstraintViolationException e2) { + out.print("Please select any party"); + RequestDispatcher rd=request.getRequestDispatcher("vote.html"); + rd.include(request,response); + } + catch(Exception e) + { + out.print(" " +e); + RequestDispatcher rd=request.getRequestDispatcher("vote.html"); + rd.include(request,response); + } + out.close(); + + +} + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doPost(request, response); +} + + + +static boolean checkLogin(String card) throws SQLException +{ + boolean r=false; + ps=con.prepareStatement("Select * from register where cardno = ?"); + ps.setString(1,card); + + ResultSet rs=ps.executeQuery(); + r=rs.next(); + + return r; +} +} diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/META-INF/MANIFEST.MF b/Online Voting System/Online_Voting_System/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 00000000..254272e1 --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.28.jar b/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.28.jar new file mode 100644 index 00000000..ac8904ee Binary files /dev/null and b/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.28.jar differ diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/lib/servlet-api.jar b/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/lib/servlet-api.jar new file mode 100644 index 00000000..11cd71a7 Binary files /dev/null and b/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/lib/servlet-api.jar differ diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/web.xml b/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..a07d6d82 --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,71 @@ + + + + + againvote + againvote + vote.com.servlet.againvote + + + againvote + /againvote + + Online_Voting_System + + againvote.html + loginpage.html + registration.html + thankyou.html + vote.html + + + + DBUtilR + DBUtilR + vote.com.servlet.DBUtilR + + + DBUtilR + /DBUtilR + + + + loginpage + loginpage + vote.com.servlet.loginpage + + + loginpage + /loginpage + + + + registration + registration + vote.com.servlet.registration + + + registration + /registration + + + + thankyou + thankyou + vote.com.servlet.thankyou + + + thankyou + /thankyou + + + + vote + vote + vote.com.servlet.vote + + + vote + /vote + + \ No newline at end of file diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/againvote.html b/Online Voting System/Online_Voting_System/src/main/webapp/againvote.html new file mode 100644 index 00000000..4da7bdd2 --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/webapp/againvote.html @@ -0,0 +1,210 @@ + + + + +Welcome + + + + + + + + + + +
+ +
+
+
+
+
+
+
+ +
+ + +
+
+

+ Welcome +

+
+
+
\ No newline at end of file diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/loginpage.html b/Online Voting System/Online_Voting_System/src/main/webapp/loginpage.html new file mode 100644 index 00000000..8beafb2d --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/webapp/loginpage.html @@ -0,0 +1,180 @@ + + + + +LOGIN + + + + + + + + + + +
+
+
+

Online Voting System

+

"The Ballot is Stronger Than Bullet"

+
+
+
+ + + + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/registration.html b/Online Voting System/Online_Voting_System/src/main/webapp/registration.html new file mode 100644 index 00000000..5b4afcf7 --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/webapp/registration.html @@ -0,0 +1,192 @@ + + + + +Register + + + + + + + + + + + +
+
+
+

REGISTRATION

+
+
+
+ +Name: +
+ + + Voter Card Number: +
+ + Contact Number: +
+ + Address: +
+ + Date Of Birth:(YYYY/MM/DD) +
+ + Email: +
+ + Enter Pin: +
+ + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/thankyou.html b/Online Voting System/Online_Voting_System/src/main/webapp/thankyou.html new file mode 100644 index 00000000..d014fdf9 --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/webapp/thankyou.html @@ -0,0 +1,91 @@ + + + + +ThankYou + + + + + + + + + + +
+
+ +

THANK YOU...!!!

+
+
+
+
+

+
Your Vote has been counted
+

+
+
+
+
+ + \ No newline at end of file diff --git a/Online Voting System/Online_Voting_System/src/main/webapp/vote.html b/Online Voting System/Online_Voting_System/src/main/webapp/vote.html new file mode 100644 index 00000000..4888f624 --- /dev/null +++ b/Online Voting System/Online_Voting_System/src/main/webapp/vote.html @@ -0,0 +1,187 @@ + + + + +Vote Here + + + + + + + + + + + +
+
+
+

Cast Your Vote

+

"Choose the right!"

+
+
+
+
+Select Party You want to vote:
+ + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/Online Voting System/README.md b/Online Voting System/README.md new file mode 100644 index 00000000..0be88591 --- /dev/null +++ b/Online Voting System/README.md @@ -0,0 +1,54 @@ +# Online-voting-system-using-servlets + +This is an Online voting system which can be used for conducting elections in online-mode. + + +-------REQUIREMENTS + + +1.apache version 10 and database connectivity + + +2.eclipse workspace + + +3.mysql-connector + + +4.servlet-api + + +-------TECHNOLOGIES USED + + +1.HTML/CSS/JavaScript for frontend + + +2.MySQL for backend + + +3.Java servlets + + +-------MUST READ !! + + +Total number of pages - 5 + + +Welcome page,Login page(For already registered candidates),Register page(for new registrations),Vote page(to select the respective vote),Thankyou page + + +1.A user needs to get registered himself/herself in the portal first. + + +2.Voterid and password are used to login the specific user. + + +3.The user can access the vote page by entering his asked credentials. + + +4.Loginpage directs you to vote page where user can cast the vote. + + +5.With one voterid vote can be casted only once and this directs to thankyoupage.