JSP实现投票系统源码!

本文展示了如何利用JSP实现一个简单的投票系统。主要包括vote.jsp、see.jsp和index.jsp三个部分,涉及文件读写、参数获取、计数更新及结果显示。通过投票页面选择选项,系统将结果存储在文本文件中,并能展示条形图进行结果展示。
摘要由CSDN通过智能技术生成

这是用文本文件作为存储载体的投票系统:

vote.java:

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]=

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值