可按Ctrl+D收藏 蚂蚁资源网

蚂蚁资源网

投票系统源码(jsp在线投票系统源码)

  • 全部评论(3)
  • wolf8668
  • 你的 switch 的代码是错误的,应该是这样的:switch($_POST['vote']){//判断选择投票的项目 case "toupiao": toupiao1(); break; default:toupiao2();}你应该把PHP的错误报告显示关掉了,所以没显示错误打开php.ini 文件找到 error_reporting,把它设置成:error_reporting = E_ALL & ~E_NOTICE
  • 2022-01-12 14:13:52
  • 510167024
  • 2022-01-12 14:12:39
  • 萨满祭司
  • 用jsp做网上投票系统 代码,我之前做过类似的投票小项目,在这里把源码发给你。你自己好好的参考一下。--------------------------package com.tv.bean;public class TVBean { private String tvName; private int tvCount; public String getTvName() { return tvName; } public void setTvName(String tvName) { this.tvName = tvName; } public int getTvCount() { return tvCount; } public void setTvCount(int tvCount) { this.tvCount = tvCount; }}------------------------------package com.tv.dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import com.tv.bean.TVBean;public class DBUtil { private Connection con; private PreparedStatement ps = null; private ResultSet rs; public void getCon(){ try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=TV","sa",""); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } public void closeCon(){ try { if(rs !=null) rs.close(); if(ps != null) ps.close(); if(con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } public ArrayList getAll(){ ArrayList al = new ArrayList(); this.getCon(); String sql = "select * from TVInfo order by tvCount desc"; try { ps = con.prepareStatement(sql); rs = ps.executeQuery(); while(rs.next()){ TVBean tb = new TVBean(); tb.setTvName(rs.getString(1)); tb.setTvCount(rs.getInt(2)); al.add(tb); } } catch (SQLException e) { e.printStackTrace(); } finally { this.closeCon(); } return al; } public boolean updateByName(String name){ this.getCon(); String sql = "update TVInfo set tvCount=tvCount+1 where tvName='"+name+"'"; try { ps = con.prepareStatement(sql); int i = ps.executeUpdate(); if(i > 0) return true; else return false; } catch (SQLException e) { e.printStackTrace(); return false; } finally { this.closeCon(); } }}---------------------------------------package com.tv.servlet;import java.io.IOException;import java.util.ArrayList;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import com.tv.dao.DBUtil;public class VoteServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); DBUtil dao = new DBUtil(); String [] name = request.getParameterValues("tvs"); int num = name.length; for(int i =0; i < num; i++){ if(dao.updateByName(name[i])){ request.setAttribute("to", "投票成功!"); ArrayList al = dao.getAll(); HttpSession session = request.getSession(); session.setAttribute("al", al); request.getRequestDispatcher("success.jsp").forward(request, response); }else{ request.setAttribute("to", "投票失败!请重新再试!"); } } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); }}-----------------------------------<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib prefix="c" uri=" ; <head> <title>电视投票</title> </head> <body> <center> <form action="vote" method="post"> <table border="1" align="center"> <tr align="center"> <td> <h2> 选择您最喜欢的电视剧并投上一票 </h2> </td> </tr> <tr> <td> <input type="checkbox" name="tvs" value="咏春" /> 咏春 </td> </tr> <tr> <td> <input type="checkbox" name="tvs" value="金婚" /> 金婚 </td> </tr> <tr> <td> <input type="checkbox" name="tvs" value="士兵突击" /> 士兵突击 </td> </tr> <tr> <td> <input type="checkbox" name="tvs" value="少年张三丰" /> 少年张三丰 </td> </tr> <tr> <td align="center"> <input type="submit" value=" 提交 " /> <input type="reset" value=" 重置 " /> </td> </tr> </table> </form> </center> </body></html>-------------------------------------第一段代码为JavaBean;第二段代码为数据库连接类;第三段代码为Servlet控制类;第四段代码为JSP显示页面。希望能够解决你的问题!
  • 2022-01-12 14:12:39
  • 商品推荐