a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁(yè) > 編程 > JSP > 正文

JSP實(shí)現(xiàn)的簡(jiǎn)單Web投票程序代碼

2024-09-05 00:22:18
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了JSP實(shí)現(xiàn)的簡(jiǎn)單Web投票程序代碼,較為詳細(xì)的分析了JSP實(shí)現(xiàn)投票功能的具體步驟與相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了JSP實(shí)現(xiàn)的簡(jiǎn)單Web投票程序。分享給大家供大家參考。具體如下:

這里使用文本文件作為數(shù)據(jù)存儲(chǔ)的投票系統(tǒng)。

1. vote.java:

 

 
  1. package vote; 
  2. import java.io.*; 
  3. import java.util.*; 
  4. public class vote { 
  5. public String filePath = ""
  6. public int n; 
  7. private File voteFile; 
  8. private BufferedReader fileRead; 
  9. private PrintWriter fileWrite; 
  10. public String systemMessage = ""
  11. private String voteStr[] = new String[10]; 
  12. public int voteNum[] = new int[10]; 
  13. public void createFile() throws FileNotFoundException { 
  14. voteFile = new File(filePath); 
  15. if (!voteFile.exists()) { 
  16. fileWrite = new PrintWriter(new FileOutputStream(filePath)); 
  17. for (int i = 0; i < n; i++) 
  18. fileWrite.println("0"); 
  19. fileWrite.close(); 
  20. public void writeFile() throws FileNotFoundException { 
  21. fileWrite = new PrintWriter(new FileOutputStream(filePath)); 
  22. for (int i = 0; i < n; i++) { 
  23. fileWrite.println(voteNum[i]); 
  24. fileWrite.close(); 
  25. public void readFile() throws FileNotFoundException { 
  26. fileRead = new BufferedReader(new FileReader(filePath)); 
  27. for (int i = 0; i < n; i++) { 
  28. try { 
  29. voteStr[i] = fileRead.readLine(); 
  30. catch (IOException f) { 
  31. voteStr[i] = "0"
  32. voteNum[i] = Integer.parseInt(voteStr[i]); 
  33. try { 
  34. fileRead.close(); 
  35. catch (IOException d) { 
  36. systemMessage = d.toString(); 

2. vote.jsp:

 

  1. <%@ page contentType="text/html; charset=gb2312" %> 
  2. <%@ page import="java.util.*"%> 
  3. <%@ page import="java.lang.*"%> 
  4. <%@ page import="java.io.*"%> 
  5. <jsp:useBean id="vote" scope="request" class="vote.vote"/> 
  6. <% 
  7. String vote1=request.getParameter("lang"); 
  8. vote.n=4; 
  9. vote.filePath="vote.txt"
  10. vote.createFile(); 
  11. vote.readFile(); 
  12. if(vote1.compareTo("0")==0) 
  13. vote.voteNum[0]++; 
  14. if(vote1.compareTo("1")==0) 
  15. vote.voteNum[1]++; 
  16. if(vote1.compareTo("2")==0) 
  17. vote.voteNum[2]++; 
  18. if(vote1.compareTo("3")==0) 
  19. vote.voteNum[3]++; 
  20. vote.writeFile(); 
  21. %> 
  22. <script language="javascript"
  23. alert("感謝你投了寶貴的一票"); 
  24. self.location="index.jsp"
  25. </script> 

3. see.jsp:

 

 
  1. <%@ page contentType="text/html; charset=gb2312" %> 
  2. <%@ page import="java.util.*"%> 
  3. <%@ page import="java.lang.*"%> 
  4. <%@ page import="java.io.*"%> 
  5. <jsp:useBean id="vote" scope="request" class="vote.vote"/> 
  6. <% 
  7. String vote1=request.getParameter("lang"); 
  8. vote.n=4; 
  9. vote.filePath="vote.txt"
  10. vote.createFile(); 
  11. vote.readFile(); 
  12. int total=0; 
  13. float voteFlo[]=new float[5]; 
  14. for(int i=0;i<4;i++) total+=vote.voteNum[i]; 
  15. for(int i=0;i<4;i++) voteFlo[i]=150*((float)vote.voteNum[i]/(float)total); 
  16. %> 
  17. <html> 
  18. <head> 
  19. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"
  20. <title>查看調(diào)查</title> 
  21. <link href="t1.css" rel="stylesheet" type="text/css"
  22. </head> 
  23. <body> 
  24. <table width="30%" border="0" class="t1"
  25. <tr>  
  26. <td colspan="2"><div align="center">調(diào)查結(jié)果</div></td> 
  27. </tr> 
  28. <tr>  
  29. <td width="18%">JSP</td> 
  30. <td width="82%"><img src="bar.gif" width=<%=voteFlo[0]%> height=8> <%=vote.voteNum[0]%></td> 
  31. </tr> 
  32. <tr>  
  33. <td>ASP</td> 
  34. <td><img src="bar.gif" width=<%=voteFlo[1]%> height=8> <%=vote.voteNum[1]%></td> 
  35. </tr> 
  36. <tr>  
  37. <td>PHP</td> 
  38. <td><img src="bar.gif" width=<%=voteFlo[2]%> height=8> <%=vote.voteNum[2]%></td> 
  39. </tr> 
  40. <tr>  
  41. <td>其他</td> 
  42. <td><img src="bar.gif" width=<%=voteFlo[3]%> height=8> <%=vote.voteNum[3]%></td> 
  43. </tr> 
  44. <tr>  
  45. <td colspan="2"><div align="center"><a href="javascript:window.close();">關(guān)閉窗口</a></div></td> 
  46. </tr> 
  47. </table> 
  48. </body> 
  49. </html> 

4. index.jsp:

 

 
  1. <%@ page contentType="text/html; charset=gb2312" %> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"
  5. <title>投票</title> 
  6. <link href="t1.css" rel="stylesheet" type="text/css"
  7. </head> 
  8. <script language="javascript"
  9. function cw() 
  10. window.open("see.jsp","mywindow"
  11. "toolbar=no,left=150,top=200,width=270,height=350,menubar=no,systemMenu=no"); 
  12. </script> 
  13. <body> 
  14. <table width="15%" height="250" align="left"
  15. <tr> 
  16. <td><form name="form1" method="post" action="vote.jsp"
  17. <table width="100%" height="250" border="1" align="center" bordercolor="#9966CC" class="t1"
  18. <tr> 
  19. <td><div align="left">你所使用的開(kāi)發(fā)語(yǔ)言</div></td> 
  20. </tr> 
  21. <tr> 
  22. <td><input type="radio" name="lang" value="0"
  23. JSP</td> 
  24. </tr> 
  25. <tr> 
  26. <td><input type="radio" name="lang" value="1"
  27. ASP</td> 
  28. </tr> 
  29. <tr> 
  30. <td><input type="radio" name="lang" value="2"
  31. PHP</td> 
  32. </tr> 
  33. <tr> 
  34. <td><input type="radio" name="lang" value="3"
  35. 其他 </td> 
  36. </tr> 
  37. <tr> 
  38. <td><div align="center"
  39. <input name="vote" type="image" src="poll.gif" width="40" height="20" border="0"
  40. <a href="javascript:cw()"><img src="see.gif" width="40" height="20" border="0"></a></div></td> 
  41. </tr> 
  42. </table> 
  43. </form></td> 
  44. </tr> 
  45. </table> 
  46. </body> 
  47. </html> 

希望本文所述對(duì)大家的JSP程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 日韩一级免费在线观看 | 99热在线播放 | 国产精品乱码一区二区三区 | 久久成人在线 | www国产亚洲精品久久网站 | 日韩免费网站 | 人人草人人干 | 欧美成人黑人xx视频免费观看 | 久久亚洲一区二区 | 黄色的网站免费观看 | 黄色网址av | 欧美性一区二区三区 | 狠狠操夜夜操天天操 | 自拍偷拍精品 | 蜜桃视频网站在线观看 | 在线观看欧美一区二区三区 | 日韩成人在线免费视频 | 韩日精品 | 久久www免费视频 | 国产精品久久久999 日本在线免费观看 | 在线观看国产视频 | 9 1在线观看 | 一区二区三区自拍 | 日韩精品一区在线 | 国产精品69毛片高清亚洲 | 人人玩人人干 | 国产高清精品一区二区三区 | 久久一 | 精品国产三级 | 成人福利视频 | 精品中文久久 | 亚洲视频在线看 | 国产精品色一区二区三区 | 五月天婷婷国产精品 | 久久久资源 | 国产伦精品一区二区三区四区视频 | 国产精品一区二区久久久久 | 国产精品自产av一区二区三区 | 不卡的av在线播放 | 免费看的黄色大片 | 视色视频在线观看 |