导航:首页 > 源码编译 > jsp投票系统源码java

jsp投票系统源码java

发布时间:2023-01-13 03:02:32

1. jsp投票系统求源代码!可以连数据库的!

<p style=line-height: 150%><SPAN style="FONT-SIZE: 12px"><STRONG>这是用文本文件作为存储载体的投票系统:</STRONG></SPAN>
<p style=line-height: 150%><SPAN style="FONT-SIZE: 12px"><STRONG>vote.java:</STRONG></SPAN>
<SPAN style="FONT-SIZE: 12px"><STRONG></STRONG> <p style=line-height: 150%>
// Java Document
package vote;
import java.io.*;
import java.util.*;
public class vote extends Object
{
public String filePath="";
public int n;
private File voteFile;
private BufferedReader fileRead;
private PrintWriter fileWrite;
public String systemMessage="";
private String voteStr[]=new String[10];
public int voteNum[]=new int[10];
public void createFile()
throws FileNotFoundException
{
voteFile=new File(filePath);
if(!voteFile.exists())
{
fileWrite=new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++) fileWrite.println("0");
fileWrite.close();
}
}
public void writeFile()
throws FileNotFoundException
{
fileWrite=new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++)
{
fileWrite.println(voteNum[i]);
}
fileWrite.close();
}
public void readFile()
throws FileNotFoundException
{
fileRead=new BufferedReader(new FileReader(filePath));
for(int i=0;i<n;i++)
{
try
{voteStr[i]=fileRead.readLine();
}
catch(IOException f)
{
voteStr[i]="0";}
voteNum[i]=Integer.parseInt(voteStr[i]);
}
try
{
fileRead.close();
}
catch(IOException d)
{
systemMessage=d.toString();
}
}
}
<p style=line-height: 150%><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><STRONG>vote.jsp:</STRONG>

<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="vote" scope="request" class="vote.vote"/>
<%
String vote1=request.getParameter("lang");
vote.n=4;
vote.filePath="vote.txt";
vote.createFile();
vote.readFile();
if(vote1.compareTo("0")==0)
vote.voteNum[0]++;
if(vote1.compareTo("1")==0)
vote.voteNum[1]++;
if(vote1.compareTo("2")==0)
vote.voteNum[2]++;
if(vote1.compareTo("3")==0)
vote.voteNum[3]++;
vote.writeFile();
%>
<script language="javascript">
alert("感谢你投了宝贵的一票");
self.location="index.jsp";
</script></SPAN></SPAN>
<p style=line-height: 150%><STRONG> </STRONG><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><STRONG>see.jsp:</STRONG>

<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="vote" scope="request" class="vote.vote"/>
<%
String vote1=request.getParameter("lang");
vote.n=4;
vote.filePath="vote.txt";
vote.createFile();
vote.readFile();
int total=0;
float voteFlo[]=new float[5];
for(int i=0;i<4;i++) total+=vote.voteNum[i];
for(int i=0;i<4;i++) voteFlo[i]=150*((float)vote.voteNum[i]/(float)total);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查看调查</title>
<link href="t1.css" rel="stylesheet" type="text/css">
</head>
<body>

<table width="30%" border="0" class="t1">
<tr>
<td colspan="2"><div align="center">调查结果</div></td>
</tr>
<tr>
<td width="18%">JSP</td>
<td width="82%"><img src="bar.gif" width=<%=voteFlo[0]%> height=8> <%=vote.voteNum[0]%></td>
</tr>
<tr>
<td>ASP</td>
<td><img src="bar.gif" width=<%=voteFlo[1]%> height=8> <%=vote.voteNum[1]%></td>
</tr>
<tr>
<td>PHP</td>
<td><img src="bar.gif" width=<%=voteFlo[2]%> height=8> <%=vote.voteNum[2]%></td>
</tr>
<tr>
<td>其他</td>
<td><img src="bar.gif" width=<%=voteFlo[3]%> height=8> <%=vote.voteNum[3]%></td>
</tr>
<tr>
<td colspan="2"><div align="center"><a href="javascript:window.close();">关闭窗口</a></div></td>
</tr>
</table>
</body>
</html>
</SPAN></SPAN>
<p style=line-height: 150%><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><STRONG>index.jsp:</STRONG>
</SPAN></SPAN>
</SPAN></SPAN> <p style=line-height: 150%><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>投票</title>
<link href="t1.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript">
function cw()
{window.open("see.jsp","mywindow","toolbar=no,left=150,top=200,width=270,height=350,menubar=no,systemMenu=no");
}
</script>
<body>
<table width="15%" height="250" align="left">
<tr>
<td><form name="form1" method="post" action="vote.jsp">
<table width="100%" height="250" border="1" align="center" bordercolor="#9966CC" class="t1">
<tr>
<td><div align="left">你所使用的开发语言</div></td>
</tr>
<tr>
<td><input type="radio" name="lang" value="0">
JSP</td>
</tr>
<tr>
<td><input type="radio" name="lang" value="1">
ASP</td>
</tr>
<tr>
<td><input type="radio" name="lang" value="2">
PHP</td>
</tr>
<tr>
<td><input type="radio" name="lang" value="3">
其他 </td>
</tr>
<tr>
<td><div align="center">
<input name="vote" type="image" src="poll.gif" width="40" height="20" border="0">
<a href="javascript:cw()"><img src="see.gif" width="40" height="20" border="0"></a></div></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
</SPAN></SPAN></SPAN>

2. (java web开发)我想做一个投票系统,需要实现到达指定时间,该投票关闭的功能。 比如,投票A

在用户点击投票按钮的时候你肯定会进行服务端访问来进行投票记录,在服务端做投票记录的时候,判断一下服务器的时间是否到了关闭投票的时间了。如果是的话,就返回,然后在网页端告诉用户投票已经截至了。如果你想一打开网页的时候就告诉用户投票已经截至的话,可以在加载投票数据之后,告诉用户。不用什么特别的框架之类的,就用jsp+servlet+jdbc就够了。

3. 怎么用jsp实现一个简单的投票系统

要简单的,就:
搞几个选项,然后提交数据,在得到提交数据时,把数据存入一个.txt文件(反正是简单,也不必用数据库了,直接用IO输入输出流,将投票结果保存在文本文件中),写几个数字(有几个选项就写几个数字,并用","等标准符号隔开),查看投票结果,读出文本中的一串数字,并用split()分隔取值。

4. 用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.;
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..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 = new DBUtil();
String [] name = request.getParameterValues("tvs");
int num = name.length;
for(int i =0; i < num; i++){
if(.updateByName(name[i])){
request.setAttribute("to", "投票成功!");
ArrayList al = .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=" http://java.sun.com/jsp/jstl/core"%><html>
<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显示页面。希望能够解决你的问题!

5. 我在网上下载的Jsp在线投票系统里的src文件夹是空的

src里放的是java源码。。他要是没用到java文件就无所谓了,要是用到java文件,class文件给你了(class文件在web-inf的classes里),也没有问题,要是用到了java文件,但是没给你类src里又没有class文件,就不能用了。
数据库也可以直接在jsp里访问的。
能不能运行你试一下不就知道了。。

6. JSP做一个在线投票系统,到这然后就不知道怎么做了啊,求大神指点

用的什么框架做的吗?
是不是默认数据库有问题?

7. 建立一个在线投票系统

可以直接用问卷星,如果想高大上可以自己编写一个网页放在服务器上

8. java做投票系统

java做投票系统,设计程序如下:

import java.util.Set; //调用java.util.Set
import java.util.HashSet;//调用java.util.HashSet
import java.util.Iterator;//调用java.util.Iterator

public class Voter { //定义类
private static final int MAX_COUNT=100; //静态变量,最大投票数,到达此数就停止投票
private static int count; //静态变量,投票数
private static Set<Voter>voters=new HashSet<Voter>(); //静态变量,存放所有已经投票的选民
private String name; //实例变量,投票人姓名

public Voter(String name){this.name=name;} //定义名字字符串函数

/**投票*/
public void voteFor(){ //投票函数
if(count==MAX_COUNT){ //如果计数结果等于投票人数最大值
System.out.println("投票活动已经结束"); //打印投票活动已经结束
return; //返回主函数
}
if(voters.contains(this)) //如果已包含投票人姓名
System.out.println(name+":你不允许重复投票!"); //打印投票人姓名和你不允许重复投票!
else{ //否则
count++; //计数加一
voters.add(this); //调用字符串函数添加投票人姓名
System.out.println(name+":感谢你投票!"); //打印投票人姓名和感谢你投票!
}
}

/**打印投票结果*/
public static void printVoteResult(){ //投票结果函数
System.out.println("当前投票数为:"+count); //打印当前投票数为,并且统计人数
System.out.println("参与投票的选民名单如下"); //打印参与投票的选民名单如下
for(Voter voter:voters){ //遍历voters集合
System.out.println(voter.name); //打印输出投票名称
}
}

public static void main(String args[]) { //主函数
Voter tom=new Voter("Tom"); //开辟空间定义元素tom
Voter mike=new Voter("Mike"); //开辟空间定义元素mike
Voter jack=new Voter("Jack"); //开辟空间定义元素jack

tom.voteFor(); //进入tom的投票函数
tom.voteFor(); //进入tom的投票函数
mike.voteFor(); //进入mike的投票函数
jack.voteFor(); //进入jack的投票函数

Voter.printVoteResult(); //投票结果打印函数

}

}

9. 网站投票系统源代码(java web)

http://www.onegreen.net/code/HTML/10633.html 你看看这个行不行 如果行的话 请采纳

10. JSP投票系统

方法一 在 appliction 中藏一个值,可以 系统年月日作为键,值为计数器,每次投票去查看下当天日期的键下的值是否到达50 ,没有到达计数器+1,进行投票,到达了则不执行投票.

方法二 在 appliction 中藏一个值,可以 固定键,值为计数器,每次投票去查看下当天日期的键下的值是否到达50 ,没有到达计数器+1,进行投票,到达了则不执行投票. 每天0:00 将值设置为0

阅读全文

与jsp投票系统源码java相关的资料

热点内容
麦当劳点餐app哪个好 浏览:581
手机网站图片压缩 浏览:170
前端程序员干嘛 浏览:564
女权主义pdf 浏览:458
阿里云服务器低价续费 浏览:337
python监控日志脚本 浏览:134
云服务器实例是什么意思 浏览:710
小寻app是做什么的 浏览:649
c语言中编译和运行 浏览:1000
画流图找循环编译原理 浏览:158
oppo手机西瓜视频的文件夹 浏览:867
骑手一般用哪个app 浏览:610
程序员老板用什么手机 浏览:848
比心app头像不通过为什么 浏览:105
加密币市值前十走势 浏览:190
单片机学习推荐课程 浏览:473
对数ln的运算法则图片 浏览:735
仿微博app源码 浏览:781
怎么取消调用app 浏览:545
程序员去哪里求助 浏览:834