Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vidyaa18 #522

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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
{

}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd" version="5.0">
<servlet>
<description></description>
<display-name>againvote</display-name>
<servlet-name>againvote</servlet-name>
<servlet-class>vote.com.servlet.againvote</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>againvote</servlet-name>
<url-pattern>/againvote</url-pattern>
</servlet-mapping>
<display-name>Online_Voting_System</display-name>
<welcome-file-list>
<welcome-file>againvote.html</welcome-file>
<welcome-file>loginpage.html</welcome-file>
<welcome-file>registration.html</welcome-file>
<welcome-file>thankyou.html</welcome-file>
<welcome-file>vote.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>DBUtilR</display-name>
<servlet-name>DBUtilR</servlet-name>
<servlet-class>vote.com.servlet.DBUtilR</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DBUtilR</servlet-name>
<url-pattern>/DBUtilR</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>loginpage</display-name>
<servlet-name>loginpage</servlet-name>
<servlet-class>vote.com.servlet.loginpage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginpage</servlet-name>
<url-pattern>/loginpage</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>registration</display-name>
<servlet-name>registration</servlet-name>
<servlet-class>vote.com.servlet.registration</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>registration</servlet-name>
<url-pattern>/registration</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>thankyou</display-name>
<servlet-name>thankyou</servlet-name>
<servlet-class>vote.com.servlet.thankyou</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>thankyou</servlet-name>
<url-pattern>/thankyou</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>vote</display-name>
<servlet-name>vote</servlet-name>
<servlet-class>vote.com.servlet.vote</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>vote</servlet-name>
<url-pattern>/vote</url-pattern>
</servlet-mapping>
</web-app>
Loading