📄 startvote.jsp
字号:
<%@page contentType="text/html;charset=gb2312" %>
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<html>
<body bgcolor="pink">
<font size="1">
<%!
int total=0;
synchronized void countTotal(){
total++;
}
%>
<%
boolean vote=true;
String name="";
name=request.getParameter("name");
if(name==null)
name="?";
name=new String(name.getBytes("ISO-8859-1"));
String IP=(String)request.getRemoteAddr();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcdriver");
}catch(ClassNotFoundException e){
}
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{
con=DriverManager.getConnection("jdbc:odbc:vote","","");
sql=con.createStatement();
rs=sql.executeQuery("select * from IP where IP="+"'"+IP+"'");
int row=0;
while(re.next())
row++;
if(row>=1)
vote=false;
}catch(SQLException ee){
}
if(name.equals("?"))
out.print("你没有投票,没有权利看选举结果");
else
if(vote){
out.print("你投了一票");
countTotal();
try{
rs=sql.executeQuery("select * from people where name="+"'"+name+"'");
rs.next();
int count=rs.getInt("count");
count++;
String condition="update peole set count="+count+" where name="+"'"+name+"'";
sql.executeUpdate(condition);
String to="insert into IP values"+"("+"'"+IP+"'"+")";
sql.executeUpdate(to);
}catch(SQLException eee){
out.print(""+eee);
}
try{
rs=sql.executeQuery("select * from people ");
out.print("<Table Border>");
out.print("<tr>");
out.print("<TH width=100>"+"姓名");
out.print("<TH width=50>"+"得票数");
out.print("<TH width=50>"+"总票数"+total);
out.print("</tr>");
while(rs.next()){
out.print("<tr>");
out.print("<TD>"+rs.getString(1)+"</TD>");
int count=rs.getInt("count");
out.print("<TD>"+count+"</TD>");
double b=(count*100)/total;
out.print("<TD>"+b+"%"+"</TD>");
out.print("</tr>");
}
out.print("</Table>");
con.close();
}catch(SQLException eeee){
out.print(""+eeee);
}
}else
out.print("你已经投过票了");
}
%>
</font>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -