online voting project prgress

Published on January 2017 | Categories: Documents | Downloads: 38 | Comments: 0 | Views: 195
of 35
Download PDF   Embed   Report

Comments

Content


Pere are some snap shoLs LhaL were Laken of Lhe pro[ecL under proaress for 1CMC submlsslonŦ
1heses are Lhe hLml resulL aeneraLed and Lhe whole codlna ls noL done veL buL we are Lrvlna Lo make lL
compleLe Llll 26
Lh
of march


Admln loaln paae

ADMINI51kA1Ck MLNU ÞAGL


IC1Lk MLNU ÞAGL


IC1ING kL5UL15 ÞAGL



Jhen a voLer wlll be realsLered bv fleld offlcer

Lhls ls Lhe rouah dlaaram of how
we wlll (candldaLeţ user or voLerţ admln) navlaaLe sLarLlna from home paae


1ab|es made |n D82 are as fo||ow(st||| |n progress to be |mp|ement ed)
AdmlnlsLraLor
CandldaLes
users
voLers
voLlna8esulLs

here is the uncomplete code for the basic validation process on server side
1.1 1AVA CLASS CODE
/ Java class used to authenticate and validate users
// Used to add users to database
package datasource;
import iava.sql.*;
import beans.Message;
public class DatabaseConnection ¦
public static String Type;
//Method which takes username and password Irom logon screen, and checks that they
//both exist in the database. It also checks that the number oI attempts has not exceeded 3.
//Depending on a condition, it sets a message bean with the relevant message
public static boolean Authenticate(String Username, String Password,
Message message) ¦
try ¦
Type ÷ "";
String Tries ÷ "";
boolean userExists ÷ Ialse;
// Register JDBC/ODBC Driver in idbc DriverManager
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷ DriverManager.getConnection("idbc:mysql:///Voting",
"","");
Statement st ÷ c.createStatement();
iI (Username.equalsIgnoreCase("")) ¦
message

.setMessage("Please enter a username");
return Ialse;
}
iI (Password.equalsIgnoreCase("")) ¦
message
.setMessage("Please enter a password");
return Ialse;
}
iava.sql.ResultSet rs ÷ st
.executeQuery("select Type, NumberTries Irom Users
where username like '"
¹ Username
¹ "' and Password like '"
¹ Password
¹ "'");
ResultSetMetaData md ÷ rs.getMetaData();
String s ÷ null;
while (rs.next()) ¦
Type ÷ rs.getString(1);
Tries ÷ rs.getString(2);
userExists ÷ true;
}
rs.close();
iI (userExists ÷÷ true) ¦
iI (Integer.parseInt(Tries) ~ 2) ¦
message
.setMessage("You have had more then 3
attempts, and have been locked out. Please contact your system administrator");
}
} else ¦
iI (updateTries(Username, message)) ¦
message
.setMessage("Invalid Username / Password. Please
check and try again");
}
}
} catch (Exception e) ¦
e.printStackTrace();
}
return true;
}
//Returns true iI username is correct but with wrong password.
//Returns Ialse iI username is incorrect with wrong password
//Updates number oI attempts
public static boolean updateTries(String UserName, Message message) ¦
try ¦
boolean userName ÷ Ialse;
int MaxTries ÷ -1;
// Register JDBC/ODBC Driver in idbc DriverManager
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷ DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs ÷ st
.executeQuery("select NumberTries Irom Users where username like '"
¹ UserName
¹ "'");
while (rs.next()) ¦
MaxTries ÷ Integer.parseInt(rs.getString(1));
iI (MaxTries ~ 2) ¦
message
.setMessage("You have had more then 3 attempts, and
have been locked out. Please contact your system administrator");
userName ÷ Ialse;
} else ¦
userName ÷ true;
}
}
st
.executeUpdate("Update Users set NumberTries ÷ " ¹ (¹¹MaxTries) ¹ "
where username like '°" ¹ UserName¹ "°'");
return userName;
} catch (Exception e) ¦
e.printStackTrace();
return Ialse;
}
}
//Method to check iI the username is not already taken when adding new users
public static boolean checkUsername(String userName) ¦
try ¦
// Register JDBC/ODBC Driver in idbc DriverManager
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷ DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs ÷ st.executeQuery("select * Irom users where Username like
'" ¹ userName ¹ "'");
boolean exists ÷ Ialse;
while (rs.next()) ¦
exists ÷ true;
}
return exists;
} catch (Exception e) ¦
e.printStackTrace();
return Ialse;
}
}

//Method to add voters to database
public static void addVoter(String name, String surname, String age, String sex, String
streetName, String town, String postcode, String number, String course, String email, String
username, String word, String password) ¦
try ¦
iI (age.equalsIgnoreCase("")) ¦
age ÷ "0";
}
//II age not speciIied, deIault to 0
// Register JDBC/ODBC Driver in idbc DriverManager
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷ DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
st.executeUpdate("insert into users (username, password, Type,
NumberTries, word) VALUES ('" ¹ username ¹ "', '" ¹ password ¹ "', 1, 0, '" ¹ word ¹ "')");
st.executeUpdate("insert into voters (IirstName, surName, age, Sex,
streetName, Town, Postcode, phoneNumber, course, email, word, username, vote1, vote2, vote3,
vote4, vote5, timestamp, voted) VALUES ('" ¹ name ¹ "', '" ¹ surname ¹ "', " ¹
Integer.parseInt(age) ¹ ", '" ¹ sex ¹ "', '" ¹ streetName ¹ "', '" ¹ town ¹ "', '" ¹ postcode ¹ "', '" ¹
number ¹ "', '" ¹ course ¹ "', '" ¹ email ¹ "', '" ¹ word ¹ "', '" ¹ username ¹ "',
'0','0','0','0','0','0','0')");
} catch (Exception e) ¦
e.printStackTrace();
}
}
// Method to add candidates to database
public static void addCandidates(String name, String Party, String age, String sex, String
town, String number, String course, String email) ¦
try ¦
iI (age.equalsIgnoreCase("")) ¦
age ÷ "0";

}
//II age not speciIied, deIault to 0
// Register JDBC/ODBC Driver in idbc DriverManager
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷ DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
st.executeUpdate("insert into candidates (Name, Party, Age, Sex, Town,
PhoneNumber, Course, email) VALUES ('" ¹ name ¹ "', '" ¹ Party ¹ "', " ¹ Integer.parseInt(age)
¹ ", '" ¹ sex ¹ "', '" ¹ town ¹ "', '" ¹ number ¹ "', '" ¹ course ¹ "', '" ¹ email ¹ "')");
} catch (Exception e) ¦
e.printStackTrace();
}
}
// Method to add Administrators to database
public static void addAdmin(String name, String surname, String email, String sex, String
username, String password, String word) ¦
try ¦
//II age not speciIied, deIault to 0
// Register JDBC/ODBC Driver in idbc DriverManager
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷ DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
st.executeUpdate("insert into users (username, password, Type,
NumberTries, word) VALUES ('" ¹ username ¹ "', '" ¹ password ¹ "', 2, 0, '" ¹ word ¹ "')");
st.executeUpdate("insert into administrator (Iirstname, surname, email,
sex, username) VALUES ('" ¹ name ¹ "', '" ¹ surname ¹ "', '" ¹ email ¹ "', '" ¹ sex ¹ "', '" ¹
username ¹ "')");
} catch (Exception e) ¦
e.printStackTrace();
}
}

// Method to check what the password is once the username and memorable word has been
entered
public static String checkMemorableWord(String userName, String word) ¦
try ¦
// Register JDBC/ODBC Driver in idbc DriverManager
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷ DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs ÷ st.executeQuery("select password Irom users where
Username like '" ¹ userName ¹ "' and word like '" ¹ word ¹ "'");
String memorableWord ÷ "";
while (rs.next()) ¦
memorableWord ÷ rs.getString(1);
}
return memorableWord;
} catch (Exception e) ¦
e.printStackTrace();
return "";
}
}
// Method to check iI the voter has not already voted
public static String checkVoted(String userName) ¦
try ¦
// Register JDBC/ODBC Driver in idbc DriverManager
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷ DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs ÷ st.executeQuery("select voted Irom voters where
username like '" ¹ userName ¹ "'");
String Voted ÷ "";
while (rs.next()) ¦
Voted ÷ rs.getString(1);

}
return Voted;
} catch (Exception e) ¦
e.printStackTrace();
return "";
}
}
}
//************************************************************//
// Encryption class used to encrypt and decrypt system's passwords//
//*************************************************************//
package datasource;
import iavax.crypto.KeyGenerator;
import iavax.crypto.Cipher;
import iava.security.Key;
import iava.security.SecureRandom;
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
// These obiects are used to read and write
// to Iile system.
import iava.io.FileInputStream;
import iava.io.FileOutputStream;
import iava.io.ObiectInputStream;
import iava.io.ObiectOutputStream;

import iava.io.FileNotFoundException;
public class Encryption ¦
//Method to encrypt the password
public static String encrypt(String password) throws Exception ¦
// This class does the actual encryption
Cipher cipher ÷ Cipher.getInstance("DES/ECB/PKCS5Padding");
// Initialise it using key got Irom the method below.
cipher.init(Cipher.ENCRYPTMODE,getKey());
// Convert the password string to an array oI bytes
byte|| passwordAsBytes ÷ password.getBytes("UTF8");
// Encrypt
byte|| encryptedPassword ÷ cipher.doFinal(passwordAsBytes);
// Convert the resulting array oI bytes to ASCII Iorm
BASE64Encoder encoder ÷ new BASE64Encoder();
return encoder.encode(encryptedPassword);
}
//Method to decrypt the password

//Takes the ascii version oI the password, and matches it to the character
public static String decrypt(String encryptedPassword) throws Exception¦
// This class does the actual decryption
Cipher cipher ÷ Cipher.getInstance("DES/ECB/PKCS5Padding");
// Initialise it using key got Irom the method below.
cipher.init(Cipher.DECRYPTMODE,getKey());
// Convert ASCII characters to an array oI bytes
BASE64Decoder decoder ÷ new BASE64Decoder();
byte||encryptedPasswordAsBytes ÷ decoder.decodeBuIIer(encryptedPassword);
// Decrypt
byte|| decryptedPassword ÷ cipher.doFinal(encryptedPasswordAsBytes);
// Convert the resulting array oI bytes to ASCII Iorm
return new String(decryptedPassword,"UTF8");
}
/* Gets the Key used Ior encryting/decrypting.
*
* The key is stored in a Iile because the same key
* used to encrypt a text MUST be used to decrypt
* it else you get a diIIerent result. The method
* is private because it is not used outside this class.
*
* The method Iirst looks Ior a Iile called "OnlineVoting.ser"
* iI it Iinds it, it loads the key Irom there and returns it
* to whichever method asks Ior it. iI it does not Iind the
* Iile, then it generates a new key, writes it to the Iile
* named above, then returns the key.
*/
private static Key getKey() throws Exception¦
Key key ÷ null;
try ¦
// Attempt to Iind the key Iile. II it is not Iound,
// Control passes to the catch block below.
ObiectInputStream in ÷ new ObiectInputStream(new
FileInputStream("OnlineVoting.ser"));
// File Iound, get the key Irom the Iile
// You need to cast the obiect read Irom the
// Iile as a key obiect.
key ÷ (Key)in.readObiect();
//close resource opened
in.close();
} catch(FileNotFoundException InIe) ¦
// key Iile doesn't exist, create key and store in Iile.
KeyGenerator generator ÷ KeyGenerator.getInstance("DES");
generator.init(new SecureRandom());
key ÷ generator.generateKey();
ObiectOutputStream out ÷ new ObiectOutputStream(new
FileOutputStream("OnlineVoting.ser"));
out.writeObiect(key);
out.close();
}
return key;
}
}
//This a a bean that stores inIormation about the admin//
package beans;
public class AdminFormBean ¦
private String IirstName ÷ "";
private String surName ÷ "";
private String sex ÷ "";
private String phonenumber ÷ "";
private String email ÷ "";
private String Username ÷ "";
private String password ÷ "";
private String rptpassword ÷ "";
private String word ÷ "";
public String getFirstName() ¦
return IirstName;
}
public void setFirstName(String IirstName) ¦
this.IirstName ÷ IirstName;
}
public String getEmail() ¦
return email;
}
public void setEmail(String email) ¦
this.email ÷ email;
}
public String getPassword() ¦
return password;
}
public void setPassword(String password) ¦
this.password ÷ password;
}
public String getPhonenumber() ¦
return phonenumber;
}
public void setPhonenumber(String phonenumber) ¦
this.phonenumber ÷ phonenumber;
}
public String getRptpassword() ¦
return rptpassword;
}
public void setRptpassword(String rptpassword) ¦
this.rptpassword ÷ rptpassword;
}
public String getSex() ¦
return sex;
}
public void setSex(String sex) ¦
this.sex ÷ sex;
}
public String getSurName() ¦
return surName;
}
public void setSurName(String surName) ¦
this.surName ÷ surName;
}
public String getUsername() ¦
return Username;
}
public void setUsername(String username) ¦
Username ÷ username;
}
public String getWord() ¦
return word;
}
public void setWord(String word) ¦
this.word ÷ word;
}
}
//This a a bean that stores inIormation about the candidates
package beans;
public class CandidatesFormBean ¦
private String IullName ÷ "";
private String age ÷ "";
private String sex ÷ "";
private String town ÷ "";
private String phonenumber ÷ "";
private String course ÷ "";
private String email ÷ "";
private String party ÷ "";
public String getFullName() ¦
return IullName;
}
public void setFullName(String IullName) ¦
this.IullName ÷ IullName;
}
public String getAge() ¦
return age;
}
public void setAge(String age) ¦
this.age ÷ age;
}
public String getCourse() ¦
return course;
}
public void setCourse(String course) ¦
this.course ÷ course;
}
public String getEmail() ¦
return email;
}
public void setEmail(String email) ¦
this.email ÷ email;
}
public String getParty() ¦
return party;
}
public void setParty(String party) ¦
this.party ÷ party;
}
public String getPhonenumber() ¦
return phonenumber;
}
public void setPhonenumber(String phonenumber) ¦
this.phonenumber ÷ phonenumber;
}
public String getSex() ¦
return sex;
}
public void setSex(String sex) ¦
this.sex ÷ sex;
}
public String getTown() ¦
return town;
}
public void setTown(String town) ¦
this.town ÷ town;
}
}
/This a a bean that stores inIormation about what messages to display to the users
package beans;
public class Message ¦
private String message ÷ "";
/**
* (return Returns the message.
*/
public String getMessage() ¦
return message;
}
/**
* (param message The message to set.
*/
public void setMessage(String message) ¦
this.message ÷ message;
}
}
//This a a bean that stores inIormation about voting results
package beans;
import iava.util.Date;
public class VoteFormBean ¦
private String vote1 ÷ "";
private String vote2 ÷ "";
private String vote3 ÷ "";
private String vote4 ÷ "";
private String vote5 ÷ "";
private String vote6 ÷ "";
private Date timeStamp ÷ new Date();
private String UserName ÷ "";
public String getVote1() ¦
return vote1;
}
public void setVote1(String vote1) ¦
this.vote1 ÷ vote1;
}
public String getVote2() ¦
return vote2;
}
public void setVote2(String vote2) ¦
this.vote2 ÷ vote2;
}
public String getVote3() ¦
return vote3;
}
public void setVote3(String vote3) ¦
this.vote3 ÷ vote3;
}
public String getVote4() ¦
return vote4;
}
public void setVote4(String vote4) ¦
this.vote4 ÷ vote4;
}
public String getVote5() ¦
return vote5;
}
public void setVote5(String vote5) ¦
this.vote5 ÷ vote5;
}
public String getVote6() ¦
return vote6;
}
public void setVote6(String vote6) ¦
this.vote6 ÷ vote6;
}
public String getUserName() ¦
return UserName;
}
public void setUserName(String userName) ¦
UserName ÷ userName;
}
public void setTimeStamp(Date timeStamp)¦
this.timeStamp ÷ timeStamp;
}
public Date getTimeStamp()¦
return timeStamp;
}
}
//This a a bean that stores inIormation about the voters
package beans;
public class VotersFormBean ¦
private String IirstName ÷ "";
private String surName ÷ "";
private String age ÷ "";
private String sex ÷ "";
private String street ÷ "";
private String town ÷ "";
private String postcode ÷ "";
private String phonenumber ÷ "";
private String course ÷ "";
private String email ÷ "";
private String Username ÷ "";
private String password ÷ "";
private String rptpassword ÷ "";
private String word ÷ "";
public String getFirstName() ¦
return IirstName;
}
public void setFirstName(String IirstName) ¦
this.IirstName ÷ IirstName;
}
public String getAge() ¦
return age;
}
public void setAge(String age) ¦
this.age ÷ age;
}
public String getCourse() ¦
return course;
}
public void setCourse(String course) ¦
this.course ÷ course;
}
public String getEmail() ¦
return email;
}
public void setEmail(String email) ¦
this.email ÷ email;
}
public String getPassword() ¦
return password;
}
public void setPassword(String password) ¦
this.password ÷ password;
}
public String getPhonenumber() ¦
return phonenumber;
}
public void setPhonenumber(String phonenumber) ¦
this.phonenumber ÷ phonenumber;
}
public String getPostcode() ¦
return postcode;
}
public void setPostcode(String postcode) ¦
this.postcode ÷ postcode;
}
public String getRptpassword() ¦
return rptpassword;
}
public void setRptpassword(String rptpassword) ¦
this.rptpassword ÷ rptpassword;
}
public String getSex() ¦
return sex;
}
public void setSex(String sex) ¦
this.sex ÷ sex;
}
public String getStreet() ¦
return street;
}
public void setStreet(String street) ¦
this.street ÷ street;
}
public String getSurName() ¦
return surName;
}
public void setSurName(String surName) ¦
this.surName ÷ surName;
}
public String getTown() ¦
return town;
}
public void setTown(String town) ¦
this.town ÷ town;
}
public String getUsername() ¦
return Username;
}
public void setUsername(String username) ¦
Username ÷ username;
}
public String getWord() ¦
return word;
}
public void setWord(String word) ¦
this.word ÷ word;
}
}

ere is the servlet classes which handle the functionalities of checking. navigating etc(not completed yet. ~in
progress¨)
SERVLET CODE
//Servlet which takes admin details, and checks the Iorm has been Iilled in correctly
//Stores admin details in AdminFormBean
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import datasource.DatabaseConnection;
import datasource.Encryption;
import beans.AdminFormBean;
import beans.Message;
public class AddAdministrator extends HttpServlet implements Servlet ¦
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
String name ÷ req.getParameter("Name");
String surname ÷ req.getParameter("SurName");
String Email ÷ req.getParameter("Email");
String Username ÷ req.getParameter("Username");
String word ÷ req.getParameter("word");
String password ÷ req.getParameter("Password");
String repeatPassword ÷ req.getParameter("rptPassword");
String sex ÷ req.getParameter("Sex");

//Bean used to store general inIormation
Message message ÷ new Message();
AdminFormBean admin ÷ new AdminFormBean();
admin.setFirstName(name);
admin.setSurName(surname);
admin.setEmail(Email);
admin.setSex(sex);
admin.setUsername(Username);
admin.setWord(word);
admin.setPassword(password);
admin.setRptpassword(repeatPassword);
HttpSession session ÷ req.getSession(true);
session.setAttribute("Message", message);
req.setAttribute("Admin", admin);
ServletContext context ÷ getServletContext();
iI ((name.equalsIgnoreCase("")) '' (surname.equalsIgnoreCase(""))
'' (Email.equalsIgnoreCase(""))
'' (Username.equalsIgnoreCase(""))
'' (password.equalsIgnoreCase(""))
'' (repeatPassword.equalsIgnoreCase(""))
'' (word.equalsIgnoreCase(""))) ¦
message
.setMessage("You have not completed all the Iields.
Please complete all mandatory Iields.");
context.getRequestDispatcher("/AddAdministrator.isp").Iorward(req,
resp);
} else iI (!password.equals(repeatPassword)) ¦
message
.setMessage("The Passwords you have entered not equal.
Please check and try again");
context.getRequestDispatcher("/AddAdministrator.isp").Iorward(req,
resp);
} else iI (DatabaseConnection.checkUsername(Username)) ¦
message
.setMessage("The username already exists. Please select
another one.");
context.getRequestDispatcher("/AddAdministrator.isp").Iorward(req,
resp);
} else ¦
try ¦
password ÷ Encryption.encrypt(password);
} catch(Exception e) ¦
e.printStackTrace();
}
DatabaseConnection.addAdmin(name, surname, Email, sex, Username,
password, word);
context.getRequestDispatcher("/AddAdminSuccess.isp")
.Iorward(req, resp);
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
}
}
//Servlet which takes candidates details, and checks the Iorm has been Iilled in correctly
//Stores candidates details in CandidatesFormBean
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import datasource.DatabaseConnection;
import datasource.Encryption;
import beans.CandidatesFormBean;
import beans.Message;
import beans.VotersFormBean;
public class AddCanditates extends HttpServlet implements Servlet ¦
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
String name ÷ req.getParameter("Name");
String age ÷ req.getParameter("Age");
String sex ÷ req.getParameter("Sex");
String Town ÷ req.getParameter("Town");
String number ÷ req.getParameter("number");
String Course ÷ req.getParameter("Course");
String Email ÷ req.getParameter("Email");
String party ÷ req.getParameter("Party");
Message message ÷ new Message();
CandidatesFormBean candidates ÷ new CandidatesFormBean();
candidates.setFullName(name);
candidates.setAge(age);
candidates.setSex(sex);
candidates.setTown(Town);
candidates.setPhonenumber(number);
candidates.setCourse(Course);
candidates.setEmail(Email);
candidates.setParty(party);
HttpSession session ÷ req.getSession(true);
session.setAttribute("Message", message);
req.setAttribute("Candidates", candidates);
ServletContext context ÷ getServletContext();
iI ((name.equalsIgnoreCase("")) '' (Town.equalsIgnoreCase(""))
'' (Email.equalsIgnoreCase(""))
'' (party.equalsIgnoreCase(""))) ¦
message
.setMessage("You have not completed all the Iields.
Please complete all mandatory Iields.");
context.getRequestDispatcher("/AddCandidates.isp").Iorward(req, resp);
} else ¦
DatabaseConnection.addCandidates(name, party, age, sex,
Town, number, Course, Email);
context.getRequestDispatcher("/AddCandidatesSuccess.isp").Iorward(req,
resp);
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
}
}
//Servlet which takes voters details, and checks the Iorm has been Iilled in correctly
//Stores voters details in VotersFormBean
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import datasource.DatabaseConnection;
import datasource.Encryption;
import beans.Message;
import beans.VotersFormBean;
public class AddVoters extends HttpServlet implements Servlet ¦
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
String name ÷ req.getParameter("Name");
String surname ÷ req.getParameter("SurName");
String age ÷ req.getParameter("Age");
String sex ÷ req.getParameter("Sex");
String streetName ÷ req.getParameter("StreetName");
String Town ÷ req.getParameter("Town");
String Postcode ÷ req.getParameter("Postcode");
String number ÷ req.getParameter("number");
String Course ÷ req.getParameter("Course");
String Email ÷ req.getParameter("Email");
String Username ÷ req.getParameter("Username");
String word ÷ req.getParameter("word");
String password ÷ req.getParameter("Password");
String repeatPassword ÷ req.getParameter("rptPassword");
Message message ÷ new Message();
VotersFormBean voters ÷ new VotersFormBean();
voters.setFirstName(name);
voters.setSurName(surname);
voters.setAge(age);
voters.setSex(sex);
voters.setStreet(streetName);
voters.setTown(Town);
voters.setPostcode(Postcode);
voters.setPhonenumber(number);
voters.setCourse(Course);
voters.setEmail(Email);
voters.setUsername(Username);

voters.setWord(word);
voters.setPassword(password);
voters.setRptpassword(repeatPassword);
HttpSession session ÷ req.getSession(true);
session.setAttribute("Message", message);
req.setAttribute("Voters", voters);
ServletContext context ÷ getServletContext();
iI (!password.equals(repeatPassword)) ¦
message
.setMessage("The Passwords you have entered not equal.
Please check and try again");
context.getRequestDispatcher("/AddVoters.isp").Iorward(req, resp);
}
else iI ((name.equalsIgnoreCase("")) '' (surname.equalsIgnoreCase(""))
'' (streetName.equalsIgnoreCase(""))
'' (Town.equalsIgnoreCase(""))
'' (Postcode.equalsIgnoreCase(""))
'' (Email.equalsIgnoreCase(""))
'' (Username.equalsIgnoreCase(""))
'' (password.equalsIgnoreCase(""))
'' (repeatPassword.equalsIgnoreCase(""))
'' (word.equalsIgnoreCase(""))) ¦
message
.setMessage("You have not completed all the Iields.
Please complete all mandatory Iields.");
context.getRequestDispatcher("/AddVoters.isp").Iorward(req, resp);
} else iI (DatabaseConnection.checkUsername(Username)) ¦
message
.setMessage("The username already exists. Please select
another one.");
context.getRequestDispatcher("/AddVoters.isp").Iorward(req, resp);
} else ¦
try ¦
password ÷ Encryption.encrypt(password);
} catch(Exception e) ¦
e.printStackTrace();
}
DatabaseConnection.addVoter(name, surname, age, sex, streetName,
Town, Postcode, number, Course, Email, Username,
word,
password);
context.getRequestDispatcher("/AddVotersSuccess.isp").Iorward(req,
resp);
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
}
}
/Servlet which takes login details, and checks the Iorm has been Iilled in correctly
//It encrypts the password, and depending on what the value is returned Irom the database,
//a message bean is set
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import beans.Message;
import datasource.DatabaseConnection;
import datasource.Encryption;
public class AdminLogin extends HttpServlet implements Servlet ¦
public AdminLogin() ¦
super();
}
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException ¦
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) ¦
try ¦
String UserName ÷ req.getParameter("Username");
String Password ÷ req.getParameter("Password");
Message message ÷ new Message();
System.out.println("Username & Password :" ¹ UserName ¹ " " ¹
Password);
Password ÷ Encryption.encrypt(Password);
DatabaseConnection.Authenticate(UserName, Password, message);
HttpSession session ÷ req.getSession();
session.setAttribute("Message", message);
ServletContext context ÷ getServletContext();
iI (!message.getMessage().equalsIgnoreCase("")) ¦
context.getRequestDispatcher("/AdminLogin.isp").Iorward(req,
resp);
} else ¦
iI (DatabaseConnection.Type.equalsIgnoreCase("2")) ¦
context.getRequestDispatcher("/AdminMenu.isp").Iorward(req,
resp);
} else ¦
message
.setMessage("Invalid Username / Password. Please
check and try again");
context.getRequestDispatcher("/AdminLogin.isp").Iorward(req,
resp);
}
}
} catch (IOException e) ¦
e.printStackTrace();
} catch (ServletException e1) ¦
e1.printStackTrace();
}catch (Exception e2) ¦
e2.printStackTrace();
}
}
}
//Servlet which takes user back to voting screen iI they wish to change who they voted Ior
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import beans.VoteFormBean;
public class BackVote extends HttpServlet implements Servlet ¦
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
HttpSession session ÷ req.getSession(true);
ServletContext context ÷ getServletContext();
context.getRequestDispatcher("/VotersMenu.isp")
.Iorward(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
}
}
// This servlet is used to validate Iorgottenpassword page and display Iorgotten passowords
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import datasource.DatabaseConnection;
import datasource.Encryption;
import beans.Message;
import beans.VotersFormBean;
public class ForgottenPassword extends HttpServlet implements Servlet ¦
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
String word ÷ req.getParameter("word");
String userName ÷ req.getParameter("userName");
Message message ÷ new Message();
HttpSession session ÷ req.getSession(true);
req.setAttribute("Message", message);
ServletContext context ÷ getServletContext();
iI ((word.equalsIgnoreCase("")) '' (userName.equalsIgnoreCase(""))) ¦
message
.setMessage("You have not completed all the Iields.
Please complete all Iields.");
context.getRequestDispatcher("/ForgottenPassword.isp").Iorward(req,
resp);
} else ¦
String memorableWord ÷ "";
memorableWord ÷
DatabaseConnection.checkMemorableWord(userName, word);
try ¦
// decrypt method called Irom databaseconnection class to
decrypt encrypted password
memorableWord ÷ Encryption.decrypt(memorableWord);
} catch(Exception e) ¦
e.printStackTrace();
}
//Validation
iI (memorableWord.equalsIgnoreCase("")) ¦
message
.setMessage("Username or memorable word is incorrect. Please
check and try again");
} else ¦
message
.setMessage("Your Password is : " ¹ memorableWord);
}
context.getRequestDispatcher("/ForgottenPassword.isp").Iorward(req,
resp);
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
}
}
//Servlet used to validate login page, directs voter to votermenu page iI successIully with login
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import beans.Message;
import beans.VoteFormBean;
import datasource.DatabaseConnection;
import datasource.Encryption;
public class Login extends HttpServlet implements Servlet ¦
static String Name ÷ "";
public Login() ¦
super();
}
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException ¦
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) ¦
try ¦
String UserName ÷ req.getParameter("Username");
String password ÷ req.getParameter("Password");
Message message ÷ new Message();
try ¦
password ÷ Encryption.encrypt(password);
} catch(Exception e) ¦
e.printStackTrace();
}
DatabaseConnection.Authenticate(UserName, password, message);
String voted ÷ DatabaseConnection.checkVoted(UserName);
HttpSession session ÷ req.getSession();
session.setAttribute("Message", message);
ServletContext context ÷ getServletContext();
iI (!message.getMessage().equalsIgnoreCase("")) ¦
context.getRequestDispatcher("/Login.isp").Iorward(req, resp);
} else ¦
iI (DatabaseConnection.Type.equalsIgnoreCase("1")) ¦
iI (voted.equalsIgnoreCase("0")) ¦
Name ÷ UserName;
context.getRequestDispatcher("/VotersMenu.isp").Iorward(
req, resp);
} else ¦
context.getRequestDispatcher("/NotAllowed.isp").Iorward(
req, resp);
}
} else ¦
message
.setMessage("Invalid Username / Password. Please
check and try again");
context.getRequestDispatcher("/Login.isp").Iorward(req,
resp);
}
}
} catch (IOException e) ¦
e.printStackTrace();
} catch (ServletException e1) ¦
e1.printStackTrace();
}
}
}
// Servlet directs user to thank you page aIter voting
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import beans.VoteFormBean;
public class ThankYou extends HttpServlet implements Servlet ¦
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
HttpSession session ÷ req.getSession(true);
ServletContext context ÷ getServletContext();
context.getRequestDispatcher("/ThankYou.isp")
.Iorward(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
}
}
/This servlet contains inIormation about the candidate that was voted Ior
package evote;
import iava.io.IOException;
import iavax.servlet.Servlet;
import iavax.servlet.ServletContext;
import iavax.servlet.ServletException;
import iavax.servlet.http.HttpServlet;
import iavax.servlet.http.HttpServletRequest;
import iavax.servlet.http.HttpServletResponse;
import iavax.servlet.http.HttpSession;
import iava.util.Date;
import beans.VoteFormBean;
public class Vote extends HttpServlet implements Servlet ¦
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException ¦
String vote1 ÷ req.getParameter("Vote1");
String vote2 ÷ req.getParameter("Vote2");
String vote3 ÷ req.getParameter("Vote3");
String vote4 ÷ req.getParameter("Vote4");
String vote5 ÷ req.getParameter("Vote5");
String vote6 ÷ req.getParameter("Vote6");
String name ÷ Login.Name;
System.out.print(name);
HttpSession session ÷ req.getSession(true);
VoteFormBean vote ÷ new VoteFormBean();
vote.setVote1(vote1);
vote.setVote2(vote2);
vote.setVote3(vote3);
vote.setVote4(vote4);
vote.setVote5(vote5);
vote.setVote6(vote6);
vote.setUserName(name);
vote.setTimeStamp(new Date(System.currentTimeMillis()));
req.setAttribute("Vote", vote);
ServletContext context ÷ getServletContext();
context.getRequestDispatcher("/ConIirmationVote.isp")
.Iorward(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException } }

ava Server Pages are as(these are also about to complete)
<!-- 1SP USED TO VIEW ADMINISTRATORS -->
·°( page language÷"iava" import÷"iava.sql.*" °~
·°
String IName ÷ "";
String lName ÷ "";
String email ÷ "";
String username ÷ "";
°~
·HTML~
·HEAD~
·°( page language÷"iava" contentType÷"text/html; charset÷ISO-8859-1"
pageEncoding÷"ISO-8859-1"°~
·META http-equiv÷"Content-Type" content÷"text/html; charset÷ISO-8859-1"~
·META http-equiv÷"Content-Style-Type" content÷"text/css"~
·LINK hreI÷"theme/Master.css" rel÷"stylesheet"
type÷"text/css"~
·TITLE~Add voters·/TITLE~
·/HEAD~
·BODY~
·H1 align÷"center"~·FONT color÷"red"~·B~Administrators Detail·/B~s·/FONT~·/H1~
·BR~
·DIV align÷"leIt"~
·TABLE border÷"0" cellspacing÷"0"
cellpadding÷"20"~
·TR~
·TD width÷"91"~·B~First Name·/B~·/TD~
·TD width÷"102"~·B~Surname·/B~·/TD~
·TD width÷"72"~·B~Email·/B~·/TD~
·TD colspan÷"1" width÷"85"~·B~Username·/B~·/TD~
·/TR~
·°
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting", "root", "");
Statement st ÷ c.createStatement();
ResultSet rs ÷ st.executeQuery("select * Irom administrator");
while (rs.next()) ¦
IName ÷ rs.getString(1);
lName ÷ rs.getString(2);
email ÷ rs.getString(3);
username ÷ rs.getString(5);
out.print("·tr~·td~" ¹ IName ¹ "·/td~·td~" ¹ lName ¹
"·/td~·td~" ¹ email ¹ "·/td~·td~" ¹ username ¹ "·/td~ ");
°~

·°
}
}catch (Exception e) ¦}°~
·/TABLE~
·BR~
·/DIV~
·DIV align÷"center"~
·CENTER~
·A
hreI÷"AdminMenu.isp"~·BR~
·/A~·A hreI÷"AdminMenu.isp"~Main Menu·/A~
·/CENTER~
·/BODY~
·/HTML~
<!-- 1SP USED TO VIEW VOTING RESULTS -->
·°( page language÷"iava" import÷"iava.sql.*" °~
·°
String vote1 ÷ "";
String count ÷ "";
int percentage ÷ 0;
int percent ÷ 0;
°~
·HTML~
·HEAD~
·°( page language÷"iava" contentType÷"text/html; charset÷ISO-8859-1"
pageEncoding÷"ISO-8859-1"°~
·META http-equiv÷"Content-Type" content÷"text/html; charset÷ISO-8859-1"~
·META http-equiv÷"Content-Style-Type" content÷"text/css"~
·LINK hreI÷"theme/Master.css" rel÷"stylesheet"
type÷"text/css"~
·TITLE~Delete Candidates·/TITLE~
·/HEAD~
·BODY~
·H1 align÷"center"~·FONT color÷"red"~·B~Candidates Detail·/B~s·/FONT~·/H1~
·P align÷"center"~·BR~
·BR~
·FONT color÷"red" size÷"¹4"~President ·/FONT~·/P~
·DIV align÷"center"~
·TABLE border÷"0" cellspacing÷"0" cellpadding÷"10"~
·TR~
·TD width÷"91"~·B~Name·/B~·/TD~
·TD width÷"72"~·B~Voting Count·/B~·/TD~
·TD width÷"72"~·B~Percentage·/B~·/TD~
·/TR~
·°
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs1 ÷ st.executeQuery("select count(vote1) Irom
voters");
while (rs1.next()) ¦
percentage ÷ Integer.parseInt(rs1.getString(1));
}
ResultSet rs ÷ st.executeQuery("select vote1, count(vote1) Irom
voters group by vote1");
while (rs.next()) ¦
vote1 ÷ rs.getString(1);
count ÷ rs.getString(2);
percent ÷ Integer.parseInt(count);
out.print("·tr~·td~" ¹ vote1 ¹ "·/td~·td~" ¹ count ¹
"·/td~·td~" ¹ (percent * 100) / percentage ¹ "°");
}
}catch (Exception e) ¦}°~
·/TABLE~
·/·P~
·P~
·FONT color÷"red" size÷"¹4"~Vice President·/FONT~·/P~
·DIV align÷"center"~
·TABLE border÷"0" cellspacing÷"0" cellpadding÷"10"~
·TR~
·TD width÷"91"~·B~Name·/B~·/TD~
·TD width÷"72"~·B~Voting Count·/B~·/TD~
·TD width÷"72"~·B~Percentage·/B~·/TD~
·/TR~
·°
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs1 ÷ st.executeQuery("select count(vote2) Irom
voters");
while (rs1.next()) ¦
percentage ÷ Integer.parseInt(rs1.getString(1));
}
ResultSet rs ÷ st.executeQuery("select vote2, count(vote2) Irom
voters group by vote2");
while (rs.next()) ¦
vote1 ÷ rs.getString(1);
count ÷ rs.getString(2);
percent ÷ Integer.parseInt(count);
out.print("·tr~·td~" ¹ vote1 ¹ "·/td~·td~" ¹ count ¹
"·/td~·td~" ¹ (percent * 100) / percentage ¹ "°");
}
}catch (Exception e) ¦}°~
·/TABLE~
·/P~
·P~
·FONT color÷"red" size÷"¹4"~Secretary·/FONT~·/P~
·DIV align÷"center"~
·TABLE border÷"0" cellspacing÷"0" cellpadding÷"10"~
·TR~
·TD width÷"91"~·B~Name·/B~·/TD~
·TD width÷"72"~·B~Voting Count·/B~·/TD~
·TD width÷"72"~·B~Percentage·/B~·/TD~
·/TR~
·°
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs1 ÷ st.executeQuery("select count(vote3) Irom
voters");
while (rs1.next()) ¦
percentage ÷ Integer.parseInt(rs1.getString(1));
}
ResultSet rs ÷ st.executeQuery("select vote3, count(vote3) Irom
voters group by vote3");
while (rs.next()) ¦
vote1 ÷ rs.getString(1);
count ÷ rs.getString(2);
percent ÷ Integer.parseInt(count);
out.print("·tr~·td~" ¹ vote1 ¹ "·/td~·td~" ¹ count ¹
"·/td~·td~" ¹ (percent * 100) / percentage ¹ "°");
}
}catch (Exception e) ¦}°~
·/TABLE~
·/P~
·P~
·FONT color÷"red" size÷"¹4"~Treasury·/FONT~·/P~
·DIV align÷"center"~
·TABLE border÷"0" cellspacing÷"0" cellpadding÷"10"~
·TR~
·TD width÷"91"~·B~Name·/B~·/TD~
·TD width÷"72"~·B~Voting Count·/B~·/TD~
·TD width÷"72"~·B~Percentage·/B~·/TD~
·/TR~
·°
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs1 ÷ st.executeQuery("select count(vote4) Irom
voters");
while (rs1.next()) ¦
percentage ÷ Integer.parseInt(rs1.getString(1));
}
ResultSet rs ÷ st.executeQuery("select vote4, count(vote4) Irom
voters group by vote4");
while (rs.next()) ¦
vote1 ÷ rs.getString(1);
count ÷ rs.getString(2);
percent ÷ Integer.parseInt(count);
out.print("·tr~·td~" ¹ vote1 ¹ "·/td~·td~" ¹ count ¹
"·/td~·td~" ¹ (percent * 100) / percentage ¹ "°");
}
}catch (Exception e) ¦}°~
·/TABLE~
·/P~
·P~
·FONT color÷"red" size÷"¹4"~Education OIIicier·/FONT~·/P~
·DIV align÷"center"~
·TABLE border÷"0" cellspacing÷"0" cellpadding÷"10"~
·TR~
·TD width÷"91"~·B~Name·/B~·/TD~
·TD width÷"72"~·B~Voting Count·/B~·/TD~
·TD width÷"72"~·B~Percentage·/B~·/TD~
·/TR~
·°
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs1 ÷ st.executeQuery("select count(vote5) Irom
voters");
while (rs1.next()) ¦
percentage ÷ Integer.parseInt(rs1.getString(1));
}
ResultSet rs ÷ st.executeQuery("select vote5, count(vote5) Irom
voters group by vote5");
while (rs.next()) ¦
vote1 ÷ rs.getString(1);
count ÷ rs.getString(2);
percent ÷ Integer.parseInt(count);
out.print("·tr~·td~" ¹ vote1 ¹ "·/td~·td~" ¹ count ¹
"·/td~·td~" ¹ (percent * 100) / percentage ¹ "°");
}
}catch (Exception e) ¦}°~
·/TABLE~
·/P~
·P~
·FONT color÷"red" size÷"¹4"~Disability OIIicier·/FONT~·/P~
·DIV align÷"center"~
·TABLE border÷"0" cellspacing÷"0" cellpadding÷"10"~
·TR~
·TD width÷"91"~·B~Name·/B~·/TD~
·TD width÷"72"~·B~Voting Count·/B~·/TD~
·TD width÷"72"~·B~Percentage·/B~·/TD~
·/TR~
·°
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
ResultSet rs1 ÷ st.executeQuery("select count(vote6) Irom
voters");
while (rs1.next()) ¦
percentage ÷ Integer.parseInt(rs1.getString(1));
}
ResultSet rs ÷ st.executeQuery("select vote6, count(vote6) Irom
voters group by vote6");
while (rs.next()) ¦
vote1 ÷ rs.getString(1);
count ÷ rs.getString(2);
percent ÷ Integer.parseInt(count);
out.print("·tr~·td~" ¹ vote1 ¹ "·/td~·td~" ¹ count ¹
"·/td~·td~" ¹ (percent * 100) / percentage ¹ "°");
}
}catch (Exception e) ¦}°~
·/TABLE~
·/P~
·/DIV~
·DIV align÷"center"~
·CENTER~
·isp:useBean id÷"Message" class÷"beans.Message" scope÷"session"~
·/isp:useBean~
·isp:getProperty name÷"Message" property÷"message" /~·A
hreI÷"AdminMenu.isp"~·BR~
·/A~·A hreI÷"AdminMenu.isp"~Main Menu·/A~
·/CENTER~
·/BODY~
·/HTML~
<!-- 1SP USED TO RETRIEVE VOTES DATA FROM VOTERS ON TE VOTER
MENU PAGE -->
·°( page language÷"iava"°~
·°( page session÷"true"°~
·°( page import÷"iava.sql.*"°~
·HTML~
·HEAD~
·°( page language÷"iava" contentType÷"text/html; charset÷ISO-8859-1"
pageEncoding÷"ISO-8859-1"°~
·META http-equiv÷"Content-Type" content÷"text/html; charset÷ISO-8859-1"~
·META http-equiv÷"Content-Style-Type" content÷"text/css"~
·LINK hreI÷"theme/Master.css" rel÷"stylesheet"
type÷"text/css"~
·TITLE~Voting·/TITLE~
·/HEAD~
·BODY~
·P~·BR~
·BR~
·/P~
·P align÷"center"~·B~·FONT color÷"red" size÷"7"~Cast your vote·/FONT~·/B~·/P~
·FORM action÷"/OnlineVoting/Vote"~
·FONT color÷"green" size÷"5"~
·p align÷"center"~
·°
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
Statement s ÷ c.createStatement();
ResultSet rs ÷ s.executeQuery("SELECT Name Irom Candidates
where Party like 'President'");
out.println("·BR~·BR~");
out.println("Student Union President: ·SELECT NAME÷" ¹
"Vote1" ¹ "~");
while (rs.next()) ¦
String val ÷ rs.getString(1);
out.println("·OPTION VALUE÷'" ¹ val ¹ "'~" ¹ val ¹
"·/OPTION~");
}
out.println("·/SELECT~");
rs ÷ s.executeQuery("SELECT Name Irom Candidates where
Party like 'Vice President'");
out.println("·BR~·BR~");
out.println("Vice President: ·SELECT NAME÷" ¹ "Vote2" ¹
"~");
while (rs.next()) ¦
String val ÷ rs.getString(1);
out.println("·OPTION VALUE÷'" ¹ val ¹ "'~" ¹ val ¹
"·/OPTION~");
}
out.println("·/SELECT~");
rs ÷ s.executeQuery("SELECT Name Irom Candidates where
Party like 'Secretary'");
out.println("·BR~·BR~");
out.println("Secretary: ·SELECT NAME÷" ¹ "Vote3" ¹ "~");
while (rs.next()) ¦
String val ÷ rs.getString(1);
out.println("·OPTION VALUE÷'" ¹ val ¹ "'~" ¹ val ¹
"·/OPTION~");
}
out.println("·/SELECT~");
rs ÷ s.executeQuery("SELECT Name Irom Candidates where
Party like 'Treasury'");
out.println("·BR~·BR~");
out.println("Treasury: ·SELECT NAME÷" ¹ "Vote4" ¹ "~");
while (rs.next()) ¦
String val ÷ rs.getString(1);
out.println("·OPTION VALUE÷'" ¹ val ¹ "'~" ¹ val ¹
"·/OPTION~");
}
out.println("·/SELECT~");
rs ÷ s.executeQuery("SELECT Name Irom Candidates where
Party like 'Education OIIicer'");
out.println("·BR~·BR~");
out.println("Education OIIicer: ·SELECT NAME÷" ¹ "Vote5"
¹ "~");
while (rs.next()) ¦
String val ÷ rs.getString(1);
out.println("·OPTION VALUE÷'" ¹ val ¹ "'~" ¹ val ¹
"·/OPTION~");
}
out.println("·/SELECT~");
rs ÷ s.executeQuery("SELECT Name Irom Candidates where
Party like 'Disability OIIicer'");
out.println("·BR~·BR~");
out.println("Disability OIIicer: ·SELECT NAME÷" ¹ "Vote6"
¹ "~");
while (rs.next()) ¦
String val ÷ rs.getString(1);
out.println("·OPTION VALUE÷'" ¹ val ¹ "'~" ¹ val ¹
"·/OPTION~");
}
out.println("·/SELECT~");
rs.close();
s.close();
}
catch (Exception e) ¦
return;
}
°~·p align÷"center"~
·INPUT type÷"submit" name÷"Submit" value÷"Submit"~
·/p~
·/FONT~
·/FORM~
·/BODY~
·/HTML~
<!-- 1SP USED TO CONFIRM VOTES FOR VOTER AND TEN UPDATE VOTES
CAST IN TE DATABASE-->
·isp:useBean id÷"Vote" class÷"beans.VoteFormBean" scope÷"request" /~
·HTML~
·HEAD~
·°( page language÷"iava" contentType÷"text/html; charset÷ISO-8859-1"
pageEncoding÷"ISO-8859-1"°~
·META http-equiv÷"Content-Type" content÷"text/html; charset÷ISO-8859-1"~
·META http-equiv÷"Content-Style-Type" content÷"text/css"~
·°( page language÷"iava" import÷"iava.sql.*"°~
·LINK hreI÷"theme/Master.css" rel÷"stylesheet" type÷"text/css"~
·TITLE~Voters Results·/TITLE~
·/HEAD~
·BODY~
·H1 align÷"center"~·FONT color÷"red"~·B~Administrator Detail·/B~s·/FONT~·/H1~
·BR~
·FONT size÷"¹2"~·B~·SPAN style÷"text-align: center"~You have voted Ior
the Iollowing, please conIirm by clicking on submit. ·BR~
II you want to amend your answers, please click on the back button ·/SPAN~·/B~·/FONT~
·BR~
·BR~
·°
// Once voter has conIirmed vote, Ilag set to 1, so user not allowed to vote again
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
Statement st ÷ c.createStatement();
st.executeUpdate("update voters set vote1 ÷ '" ¹ Vote.getVote1()
¹ "', vote2 ÷ '" ¹ Vote.getVote2() ¹ "', vote3 ÷ '"
¹ Vote.getVote3()
¹ "', vote4 ÷ '" ¹ Vote.getVote4() ¹ "', vote5 ÷ '"
¹ Vote.getVote5()
¹ "', vote6 ÷ '" ¹ Vote.getVote6()
¹ "', timestamp ÷ '" ¹ Vote.getTimeStamp() ¹ "',
voted ÷ '1' where username ÷ '" ¹ Vote.getUserName() ¹ "'");
st.close();
} catch (Exception e) ¦out.println(e);}
try ¦
Class.IorName("com.mysql.idbc.Driver").newInstance();
Connection c ÷
DriverManager.getConnection("idbc:mysql:///Voting");
long millisecs ÷ System.currentTimeMillis() ;
Timestamp ts ÷ new iava.sql.Timestamp(millisecs) ;
Statement st ÷ c.createStatement();
st.executeUpdate("update voters set timestamp ÷ '" ¹ ts ¹ "'");
st.close();
} catch (Exception e) ¦out.println(e);}
°~
·FORM action÷"/OnlineVoting/ThankYou"~
·DIV align÷"leIt"~
·TABLE border÷"0" width÷"70" height÷"10" cellspacing÷"0"
cellpadding÷"10"~
·TBODY~
·TR~
·TD nowrap width÷"30°"~·B~·FONT Iace÷"MicrosoIt Sans
SeriI"
color÷"red"~Student Union
President:·/FONT~·/B~·/TD~
·TD width÷"36"~·/TD~
·TD width÷"92"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~·°÷Vote.getVote1()°~·/FONT~·/B~·/TD~
·/TR~
·TR~
·TD nowrap width÷"30°"~·B~·FONT Iace÷"MicrosoIt Sans
SeriI"
color÷"red"~Vice President:·/FONT~·/B~·/TD~
·TD width÷"36"~·/TD~
·TD width÷"92"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~·°÷Vote.getVote2()°~·/FONT~·/B~·/TD~
·/TR~
·TR~
·TD nowrap width÷"30°"~·B~·FONT Iace÷"MicrosoIt Sans
SeriI"
color÷"red"~Secretary:·/FONT~·/B~·/TD~
·TD width÷"36"~·/TD~
·TD width÷"92"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~·°÷Vote.getVote3()°~·/FONT~·/B~·/TD~
·/TR~
·TR~
·TD width÷"51"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~Treasury:·/FONT~·/B~·/TD~
·TD width÷"36"~·/TD~
·TD width÷"36"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~·°÷Vote.getVote4()°~·/FONT~·/B~·/TD~
·TR~
·TD width÷"51"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~Education
OIIicier:·/FONT~·/B~·/TD~
·TD width÷"36"~·/TD~
·TD width÷"36"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~·°÷Vote.getVote5()°~·/FONT~·/B~·/TD~
·/TR~
·TR~
·TD width÷"51"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~Disability
OIIicier:·/FONT~·/B~·/TD~
·TD width÷"36"~·/TD~
·TD width÷"36"~·B~·FONT Iace÷"MicrosoIt Sans SeriI"
color÷"red"~·°÷Vote.getVote6()°~·/FONT~·/B~·/TD~
·/TR~
·/TBODY~
·/TABLE~
·BR~
·CENTER~·INPUT type÷"submit" name÷"Submit" value÷"Submit"~·/CENTER~
·/DIV~
·/FORM~
·FORM action÷"/OnlineVoting/BackVote"~
·CENTER~·INPUT type÷"submit" name÷"Back" value÷"Back"~·/CENTER~
·/FORM~
·FONT color÷"red"~ ·BR~
·/FONT~
·DIV align÷"center"~
·CENTER~·/CENTER~
·/BODY~
·/HTML~
1.4 TML CODE
·!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"~
·HTML~
·HEAD~
·META http-equiv÷"Content-Type" content÷"text/html; charset÷ISO-8859-1"~
·META http-equiv÷"Content-Style-Type" content÷"text/css"~
·LINK hreI÷"theme/Master.css" rel÷"stylesheet"
type÷"text/css"~
·TITLE~Main Menu·/TITLE~
·/HEAD~
·BODY~
·H1 align÷"center"~·I~·U~·B~·FONT color÷"red" Iace÷"Tahoma"~Welcome to
e-voting·/FONT~·/B~·/U~·/I~·/H1~
·H2 align÷"center"~·BR~Please select an option
·/H2~
·P~·BR~
·Center~
·B~·A hreI÷"Login.html"~1. Voter's Login·/A~·BR~·BR~
·A hreI÷"AdminLogin.html"~2. Administrator's Login·/A~·/B~
·/P~
·p align÷"center"~ ·B~ ·a hreI÷"HomePage.htm"~ Home Page
·/a~ ·/B~·/p~
·/BODY~

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close