簡單的投票系統,但是顯示的時候出現問題,希望高手解答。

tiansong163發表於2010-10-23
vote.jsp
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>投票選擇</title>
</head>
<body>
<%
Connection con = null;
Statement sql = null;
ResultSet rs = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
out.println("載入不成功...");
}
try {
con = DriverManager.getConnection("jdbc:odbc:vote", "", "");
sql = con.createStatement();
rs = sql.executeQuery("select *from people");
out.print("<form action=startvote.jsp method=post >");
out.print("<table border>");
out.print("<tr>");
out.print("<td>");
out.print("姓名");
out.print("</td>");
out.print("<td>");
out.print("投票選擇");
out.print("</td>");
out.print("</tr>");
while (rs.next()) {
String name = rs.getString(1);
out.print("<tr>");
out.print("<td>");
out.print(name);
out.print("</td>");
out.print("<td>");
out.print("<input type=radio name=name >");
out.print("</td>");
out.print("</tr>");
}
out.print("</table>");
out.print("<input type=submit value=提交>");
out.print("</form>");
rs.close();
sql.close();
con.close();
} catch (Exception e) {
out.println("連線不成功...");
}
%>
</body>
</html>

startvote.jsp
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>投票選擇</title>
</head>
<body>
<%
Connection con = null;
Statement sql = null;
ResultSet rs = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
out.println("載入不成功...");
}
try {
con = DriverManager.getConnection("jdbc:odbc:vote", "", "");
sql = con.createStatement();
rs = sql.executeQuery("select *from people");
out.print("<form action=startvote.jsp method=post >");
out.print("<table border>");
out.print("<tr>");
out.print("<td>");
out.print("姓名");
out.print("</td>");
out.print("<td>");
out.print("投票選擇");
out.print("</td>");
out.print("</tr>");
while (rs.next()) {
String name = rs.getString(1);
out.print("<tr>");
out.print("<td>");
out.print(name);
out.print("</td>");
out.print("<td>");
out.print("<input type=radio name=name >");
out.print("</td>");
out.print("</tr>");
}
out.print("</table>");
out.print("<input type=submit value=提交>");
out.print("</form>");
rs.close();
sql.close();
con.close();
} catch (Exception e) {
out.println("連線不成功...");
}
%>
</body>
</html>

相關文章