📄 dealvote.jsp
字号:
<!--dealvote.jsp-->
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<%!
public String codeString(String s){
String str=s;
try{
byte b[]=str.getBytes("ISO-8859-1");
str=new String (b);
return str;
}catch(Exception e){return str;}
}
%>
<html>
<head>
<title>Vote</title>
</head>
<body bgcolor=#C0C0C0>
<center>
<%
Connection con;
Statement sql;
String condition;
ResultSet rs;
String name;
int count;
String ID=request.getParameter("voter");
if(ID==null)ID="";
ID=codeString(ID);
name=request.getParameter("radio");
if(name==null)name="";
name=codeString(name);
String newname=request.getParameter("newname");
if(newname==null)newname="";
name=codeString(name);
if(
(!ID.equals(""))&&
(!(name.equals("")&&newname.equals("")))
){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vote","","");
sql=con.createStatement();
condition="SELECT * FROM ID WHERE ID='"+ID+"'";
rs=sql.executeQuery(condition);
if(rs.next()){
out.print("您已经投过票了!");
}
else{
if(name.equals(""))name=newname;
condition="SELECT * FROM vote WHERE name='"+name+"'";
rs=sql.executeQuery(condition);
if(rs.next()){
count=rs.getInt(2)+1;
condition="UPDATE vote SET count="+count+" WHERE name='"+name+"'";
sql.executeUpdate(condition);
}else{
condition="INSERT INTO vote VALUES ('"+name+"',1)";
sql.executeUpdate(condition);
}
out.print("您投票成功了!");
condition="INSERT INTO ID VALUES ('"+ID+"')";
sql.executeUpdate(condition);
}
con.close();
}
catch(SQLException e ){
out.print(e);
}
catch(ClassNotFoundException e){
out.print(e);
}
}else{
out.print("你提交的表单有误,请重新填写!");
}
%>
<h1>投票结果 </h1>
<br>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vote","","");
sql=con.createStatement();
condition="SELECT *FROM vote ORDER BY count DESC";
rs=sql.executeQuery(condition);
%>
<table width="300" border="1" height="25">
<tr width="300" height="25">
<td width="200">姓名</td>
<td width="100">票数</td>
</tr>
<%
while(rs.next()){
name=rs.getString(1);
count=rs.getInt(2);
if(name!=null){
%>
<tr width="300" height="25">
<td width="200"><%=name%></td>
<td width="100"><%=count%></td>
</tr>
<%
}
}
con.close();
}
catch(SQLException e ){
out.print(e);
}
catch(ClassNotFoundException e){
out.print(e);
}
%>
</table>
<br>
<a href="vote.jsp">返回 </a>
</center>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -