当前位置:首页 » 操作系统 » 投票系统jsp源码

投票系统jsp源码

发布时间: 2023-12-05 03:53:33

Ⅰ 用jsp做网上投票系统 代码

网上投票系统
jsp完成
服务器:Tomcat
开发工具:myeclipse or eclipse

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(); //投票结果打印函数

}

}

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

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

Ⅳ 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>

热点内容
电脑怎样编程 发布:2024-10-18 12:06:55 浏览:528
图的邻接表存储及遍历 发布:2024-10-18 12:02:31 浏览:495
如何查询电脑型号的配置 发布:2024-10-18 11:57:42 浏览:273
如何开张一个租赁服务器 发布:2024-10-18 11:46:13 浏览:826
python解析json文件 发布:2024-10-18 11:29:34 浏览:311
编译程序的生成程序 发布:2024-10-18 11:29:27 浏览:404
轨迹处理算法 发布:2024-10-18 11:22:25 浏览:783
支付密码怎么破解 发布:2024-10-18 11:09:19 浏览:145
线性链表c语言 发布:2024-10-18 11:09:17 浏览:785
淘宝卖的脚本可靠吗 发布:2024-10-18 10:54:04 浏览:120