欢迎来到天天文库
浏览记录
ID:51690621
大小:43.45 KB
页数:5页
时间:2020-03-15
《JSP实现投票系统源码.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、这是用文本文件作为存储载体的投票系统:vote.java:packagevote;importjava.io.*;importjava.util.*;publicclassvoteextendsObject{ publicStringfilePath=""; publicintn; privateFilevoteFile; privateBufferedReaderfileRead; privatePrintWriterfileWrite; publicStringsystemMessage=""; privateString
2、voteStr[]=newString[10]; publicintvoteNum[]=newint[10]; publicvoidcreateFile() throwsFileNotFoundException{ voteFile=newFile(filePath); if(!voteFile.exists()) { fileWrite=newPrintWriter(newFileOutputStream(filePath)); for(inti=0;i3、)fileWrite.println("0"); fileWrite.close(); }}publicvoidwriteFile() throwsFileNotFoundException { fileWrite=newPrintWriter(newFileOutputStream(filePath)); for(inti=0;i4、); }publicvoidreadFile() throwsFileNotFoundException { fileRead=newBufferedReader(newFileReader(filePath)); for(inti=0;i5、 { voteStr[i]="0";} voteNum[i]=Integer.parseInt(voteStr[i]); } try { fileRead.close(); } catch(IOExceptiond) { systemMessage=d.toString(); } }} 6、 vote.jsp:<%@pagecontentType="text/html;charset=gb2312"language="java"errorPage=""%><%@pageimport="java.util.*"%><%@pageimport="java.lang.*"%><%@pageimport="java.io.*"%><%Stringvote1=request.getParameter("l7、ang");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.writeFi8、le();%> alert("感谢你投了宝贵的一票"); self.location="index.jsp"; see.jsp:<%@pagecontentType="text/html;ch
3、)fileWrite.println("0"); fileWrite.close(); }}publicvoidwriteFile() throwsFileNotFoundException { fileWrite=newPrintWriter(newFileOutputStream(filePath)); for(inti=0;i4、); }publicvoidreadFile() throwsFileNotFoundException { fileRead=newBufferedReader(newFileReader(filePath)); for(inti=0;i5、 { voteStr[i]="0";} voteNum[i]=Integer.parseInt(voteStr[i]); } try { fileRead.close(); } catch(IOExceptiond) { systemMessage=d.toString(); } }} 6、 vote.jsp:<%@pagecontentType="text/html;charset=gb2312"language="java"errorPage=""%><%@pageimport="java.util.*"%><%@pageimport="java.lang.*"%><%@pageimport="java.io.*"%><%Stringvote1=request.getParameter("l7、ang");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.writeFi8、le();%> alert("感谢你投了宝贵的一票"); self.location="index.jsp"; see.jsp:<%@pagecontentType="text/html;ch
4、); }publicvoidreadFile() throwsFileNotFoundException { fileRead=newBufferedReader(newFileReader(filePath)); for(inti=0;i5、 { voteStr[i]="0";} voteNum[i]=Integer.parseInt(voteStr[i]); } try { fileRead.close(); } catch(IOExceptiond) { systemMessage=d.toString(); } }} 6、 vote.jsp:<%@pagecontentType="text/html;charset=gb2312"language="java"errorPage=""%><%@pageimport="java.util.*"%><%@pageimport="java.lang.*"%><%@pageimport="java.io.*"%><%Stringvote1=request.getParameter("l7、ang");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.writeFi8、le();%> alert("感谢你投了宝贵的一票"); self.location="index.jsp"; see.jsp:<%@pagecontentType="text/html;ch
5、 { voteStr[i]="0";} voteNum[i]=Integer.parseInt(voteStr[i]); } try { fileRead.close(); } catch(IOExceptiond) { systemMessage=d.toString(); } }}
6、 vote.jsp:<%@pagecontentType="text/html;charset=gb2312"language="java"errorPage=""%><%@pageimport="java.util.*"%><%@pageimport="java.lang.*"%><%@pageimport="java.io.*"%><%Stringvote1=request.getParameter("l
7、ang");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.writeFi
8、le();%> alert("感谢你投了宝贵的一票"); self.location="index.jsp"; see.jsp:<%@pagecontentType="text/html;ch
此文档下载收益归作者所有