• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

JSP实现的简单Web投票程序代码

java 搞代码 4年前 (2022-01-05) 24次浏览 已收录 0个评论

这篇文章主要介绍了JSP实现的简单Web投票程序代码,较为详细的分析了JSP实现投票功能的具体步骤与相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了JSP实现的简单Web投票程序。分享给大家供大家参考。具体如下:

这里使用文本文件作为数据存储的投票系统。

1. vote.java:

 package vote; import java.io.*; import java.util.*; 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<i style="color:transparent">来源gaodai$ma#com搞$$代**码)网</i> (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(); } } } 

2. vote.jsp:

 

3. see.jsp:

 <% 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  <title>查看调查</title> <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%"> height=8> </td></tr><tr> <td>ASP</td><td> height=8> </td></tr><tr> <td>PHP</td><td> height=8> </td></tr><tr> <td>其他</td><td> height=8> </td></tr><tr> <td colspan="2"><div align="center">关闭窗口</div></td></tr></table>

4. index.jsp:

   <title>投票</title> <table width="15%" align="left"> <tr> <td> <table width="100%" border="1" align="center" class="t1"> <tr> <td><div align="left">你所使用的开发语言</div></td></tr><tr> <td> JSP</td></tr><tr> <td> ASP</td></tr><tr> <td> PHP</td></tr><tr> <td> 其他 </td></tr><tr> <td><div align="center"> </div></td></tr></table></td></tr></table>

希望本文所述对大家的JSP程序设计有所帮助。

以上就是JSP实现的简单Web投票程序代码的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:JSP实现的简单Web投票程序代码

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址