
正文
网站自动投票java代码 网页自动投票脚本
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
jsp投票系统求源代码!可以连数据库的!
p style=line-height: 150%SPAN style="FONT-SIZE: 12px"STRONG这是用文本文件作为存储载体的投票系统:/STRONG/SPAN
p style=line-height: 150%SPAN style="FONT-SIZE: 12px"STRONGvote.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;in;i++) fileWrite.println("0");
fileWrite.close();
}
}
public void writeFile()
throws FileNotFoundException
{
fileWrite=new PrintWriter(new FileOutputStream(filePath));
for(int i=0;in;i++)
{
fileWrite.println(voteNum[i]);
}
fileWrite.close();
}
public void readFile()
throws FileNotFoundException
{
fileRead=new BufferedReader(new FileReader(filePath));
for(int i=0;in;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"STRONGvote.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 /STRONGSPAN style="LINE-HEIGHT: 15pt"SPAN style="FONT-SIZE: 12px"STRONGsee.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;i4;i++) total+=vote.voteNum[i];
for(int i=0;i4;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
tdASP/td
tdimg src="bar.gif" width=%=voteFlo[1]% height=8 %=vote.voteNum[1]%/td
/tr
tr
tdPHP/td
tdimg src="bar.gif" width=%=voteFlo[2]% height=8 %=vote.voteNum[2]%/td
/tr
tr
td其他/td
tdimg 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"STRONGindex.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
tdform name="form1" method="post" action="vote.jsp"
table width="100%" height="250" border="1" align="center" bordercolor="#9966CC" class="t1"
tr
tddiv align="left"你所使用的开发语言/div/td
/tr
tr
tdinput type="radio" name="lang" value="0"
JSP/td
/tr
tr
tdinput type="radio" name="lang" value="1"
ASP/td
/tr
tr
tdinput type="radio" name="lang" value="2"
PHP/td
/tr
tr
tdinput type="radio" name="lang" value="3"
其他 /td
/tr
tr
tddiv 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
相关问答
Q1: 用java编写一个统计投票结果程序
先定义一个学生的对象,里面有名字,和票数两个属性,再定义一个排序函数,返回值为数组,就是取得三个数的数组,打印输出,或者可以自己想一个更加面向对象的结构实现,在简单问题上多用面向对象去思考问题 。
import java.util.Scanner;
public class Test {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int cj, yxsum = 0, tgsum = 0, bjgsum = 0;
while ((cj = in.nextInt()) != 0) {
if (cj = 85) {
yxsum++;
} else if (cj = 60) {
tgsum++;
} else {
bjgsum++;
System.out.println(yxsum);
System.out.println(tgsum);
System.out.println(bjgsum);
}
扩展资料:
当编辑并运行一个Java程序时,需要同时涉及到这四种方面。使用文字编辑软件(例如记事本、写字板、UltraEdit等)或集成开发环境(Eclipse、MyEclipse等)在Java源文件中定义不同的类;
通过调用类(这些类实现了Java API)中的方法来访问资源系统,把源文件编译生成一种二进制中间码,存储在class文件中,再通过运行与操作系统平台环境相对应的Java虚拟机来运行class文件,执行编译产生的字节码,调用class文件中实现的方法来满足程序的Java API调用。
参考资料来源:百度百科-Java
Q2: JAVA语言中用于投票器的代码如何写
把投票的信息放在 ServletContext对象 中。也就是 JSP 内置对象中的application对象。因为投票信息是所有用户都要看的信息网站自动投票java代码,所以要把他放在 ServletContext对象 中。这样只要是 应用一加载就会创建 ServletContext对象 直到应用销毁网站自动投票java代码,也就是服务器关闭时,ServletContext对象 才销毁。这样就使得所有用户公用一个对象存储信息。具体的实现那要根据网站自动投票java代码你自己的需求,具体设计。
public class CServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int n = 0;ServletContext application = getServletContext();Integer num = (Integer) application.getAttribute("num");if (num != null) {n = num;}application.setAttribute("num", ++n);response.setContentType("text/html;charset=utf-8");PrintWriter out = response.getWriter();out.println("你是第" + n + "个访问者");}}
上面是个类似的例子。你可以参考一下。package servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;这是需要导入的包
Q3: java做投票系统
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 SetVotervoters=new HashSetVoter(); //静态变量,存放所有已经投票网站自动投票java代码的选民
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("参与投票网站自动投票java代码的选民名单如下"); //打印参与投票的选民名单如下
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代码和网页自动投票脚本的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







