JSP实现在线投票系统之完美版

您所在的位置:网站首页 投票网页怎么制作 JSP实现在线投票系统之完美版

JSP实现在线投票系统之完美版

2024-03-16 15:50| 来源: 网络整理| 查看: 265

       此程序是在前人的版本中,经本博主认真调试更改完善的Web程序。其中实现了文件的创建,单选(radio)是否选择的判断及跳转,鼠标事件的提示(alt)及对文件的读取、存储等等。

下面是实现过程:

vote.java

package vote; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; public class vote{ 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(); } } }

index.jsp

投票 function cw(){ //弹出查看投票结果窗口 window.open("see.jsp","mywindow","left = 550,top = 200,width = 270,height = 350");//menubar:是否显示菜单栏 ;toolbar:是否显示工具栏 ;systemMenu:系统菜单 } function check(){ //判断投票是否选择 var result=false; for(var i=0;i My JSP 'vote.jsp' starting page alert("感谢你的投票。"); self.location = "index.jsp";



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3