<%@ page import="p1.*" session="true"%> <html> <head> <title>My Page</title> </head> <body BGCOLOR="GREEN"> <H1><center>CAST YOUR VOTE</CENTER></H1> <div align="center"> <form action="#"> <% String cname=""; String cid=""; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:zeal"); PreparedStatement ps = con.prepareStatement("select c_name,id from candidate"); ResultSet rs=ps.executeQuery(); %> <table> <th> <td>CANDIDATES NAME</td> <td>VOTE</td> </th> <% while(rs.next()) { cname=rs.getString(1); cid=rs.getString(2); out.print("<tr><td>"+cname+"</td></tr>"+"<tr><td>"+"<input type="radio" name="group1" value="cid">"+"</tr></td>"); } } catch(Exception e) { } %> <input type="submit" name="submit"> </div> </form> </body> </html>
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class CastVote extends HttpServlet{ public void doGet(HttpServletRequest request,HttpServleResponse response)throws ServletException,IOException { cid=request.getParameter("id"); vid=request.getParameter("uid"); } try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:zeal"); PreparedStatement ps=con.prepareStatement("update candidate set no_of_votes=no_of_votes+1 where id="cid"); ResultSet rs=ps.executeUpdate(); con.close(); } catch(Exception e) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)