各位大哥,请教一下,怎样添加删除项,达到删除投票项的目的,(那又如何进行添加项呢)
survey.jsp页面<%@page contentType="text/html;charset=GBK"%>
<%@page language="java" import="java.sql.*"%>
<html>
<head>
<title>网上调查表</title>
</head>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
Connection con=DriverManager.getConnection("jdbc:odbc:test");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("select*from vote");
%>
<body bg="#FFCCCC">
<center>
<font face="隶书" size="5">调查问卷,请你投票:</font><br>
<font face="隶书" size="5">你认为世界杯哪只球队能够夺冠</font>
<form action="vote.jsp">
<Table width="114" border bgcolor="#FFFFCC">
<%
while (rs.next()) {
%>
<tr>
<td>
<input type="radio" name="type" value=<%=rs.getInt("id")%>>
<%=rs.getString("country")%>
</td>
</tr>
<%
}
rs.close();
con.close();
} catch (SQLException e1) {
}
%>
<tr align="center">
<td>
<input type="submit" value="投票">
</td>
</tr>
</table>
</form>
<br>
<A href="view.jsp">查看投票</A>
</center>
</body>
</html>
投票处理页面
vote.jsp
<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
Connection con=DriverManager.getConnection("jdbc:odbc:test");
Statement sql=con.createStatement();
ResultSet rs;
String rb=request.getParameter("type");
if(rb!=null&&rb!=""){
String condition="Update vote Set numb=numb+1 where id=" +rb;
sql.executeUpdate(condition);
}
con.close();
}
catch(SQLException event){}
%>
<jsp:forward page="view.jsp"/>
投票结果显示
view.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Connect SQL Server Test</title>
<style type="text/css">
body{margin:0px auto;padding:0px;font-size:12px;text-align:center;}
div,h3{margin:0px;padding:0px;}
#body{margin:10px auto;padding:10px;width:400px;border:1px solid #EEEEEE;background:#F7F7F7;line-height:22px;text-align:left;}
#body h3{color:#CC0000;margin-bottom:10px;border-bottom:2px solid #CC0000;text-indent:10px;font-size:14px;}
#body strong{border-bottom:1px solid #888888;}
</style>
</head>
<body>
<div id="body">
<h3>投票数为:</h3>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:test");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM vote");
out.println("<strong><font color=\"#008800\">id</font> -- <font color=\"#0000FF\"> content </font> -- <font color=\"#CC0000\"> numd</font></strong><br>");
while(rs.next()){
out.println("<font color=\"#008800\">" + rs.getString("id") + "</font> -------- <font color=\"#0000FF\">" + rs.getString("country") + "</font> -------- <font color=\"#CC0000\">" + rs.getString("numb") + "</font><br>");
}
rs.close();
stmt.close();
conn.close();
%>
</div>
<a href="survey.jsp">返回投票</a>
</body>
</html>
[ 本帖最后由 yuweilong012 于 2010-12-5 09:30 编辑 ]