ASP在線問答的實例代碼_ASP教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:ASP利用XML打包指定文件夾 并上傳到WEB目錄中,自行解包
      '======================== '文件1 'Pack.asp '更改 Cpathname 這一變量 '將在當前目錄生成一個DATA.XML文件 '將DATA.XML及文件2(install.asp)上傳至WEB根目錄 '運行install.asp解包 '手動刪除以上兩個文件 '======================== % Option Explic

      ASP在線問答的實例代碼首先,是HTML文件,為Test.asp,代碼如下:

      1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
      2. <
      3. if session("username")="" then 
      4. Response.Write("<script>alert('請登陸后在進行操作!');window.location='login.asp?reURL=Test.asp';</script>") 
      5. Response.End() 
      6. end if 
      7. %> 
      8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      9. <html xmlns="http://www.w3.org/1999/xhtml"> 
      10. <head> 
      11. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
      12. <title>情景問答</title> 
      13. <style type="text/css"> 
      14. <!-- 
      15. body {}{ 
      16. font-size: 12px; 
      17. color: #0066FF; 
      18. input {}{ 
      19. border: 1px solid #FFFFFF; 
      20. background-color: #EEEEEE; 
      21. left: 1px; 
      22. top: 1px; 
      23. right: 1px; 
      24. bottom: 1px; 
      25. clip: rect(10px,10px,10px,10px); 
      26. margin: 1px; 
      27. padding: 1px; 
      28.  
      29. --> 
      30. </style> 
      31. </head> 
      32. <script language="javascript"> 
      33. <!-- 
      34. function chkForm() 
      35. var e = document.frm; 
      36. var it,flag,i; 
      37. flag = false
      38.  
      39.  
      40. for(i = 1;i<=10;i++) 
      41. var it = eval("e.Question"+i); 
      42. var itLen = eval("e.Question"+i+".length"); 
      43.  
      44. for(var j = 0;j<itLen;j++) 
      45. var itChk = eval("e.Question"+i+"["+j+"].checked"); 
      46.  
      47. if(itChk) 
      48. flag = true
      49. break; 
      50.  
      51. if(!itChk && j == itLen-1) 
      52. flag = false
      53. break; 
      54.  
      55. if(!flag) 
      56. alert("請選擇第"+i+"題答案"); 
      57. return false; 
      58.  
      59. if(!flag) 
      60. alert("請選擇第"+i+"題答案"); 
      61. eval("e.Question"+i+".focus()"); 
      62. return false; 
      63. return true; 
      64. --> 
      65. </script> 
      66. <body> 
      67. <div><strong>情景問答</strong></div> 
      68. <form name="frm" action="Test_do.asp" method="post" onsubmit="return(chkForm());"> 
      69. <p><br /> 
      70. 1. 遺忘黯淡中的女主角叫什么名字?<br /> 
      71. <label> 
      72. <input type="radio" name="Question1" value="A" /> 
      73. A.</label> 
      74. Lan<br /> 
      75. <label> 
      76. <input type="radio" name="Question1" value="B" /> 
      77. B.</label> 
      78. Jenny<br /> <label> 
      79. <input type="radio" name="Question1" value="C" /> 
      80. C.</label> Lucy</p> 
      81. <p>2. 音樂往事中酒吧的名字是什么?<br /> 
      82. <label> 
      83. <input type="radio" name="Question2" value="A" /> 
      84. A.</label> 
      85. 遺忘<br /> 
      86. <label> 
      87. <input type="radio" name="Question2" value="B" /> 
      88. B.</label> 
      89. NV<br /> 
      90. <label> 
      91. <input type="radio" name="Question2" value="C" /> 
      92. C.</label> 
      93. 如影隨形</p> 
      94. <p>3.遺忘黯淡中的照片墻上有什么照片?<br /> 
      95. <label> 
      96. <input type="radio" name="Question3" value="A" /> 
      97. A.</label> 
      98. 從前的女主人公<br /> 
      99. <label> 
      100. <input type="radio" name="Question3" value="B" /> 
      101. B.</label> 
      102. 海邊的風景<br /> 
      103. <label> 
      104. <input type="radio" name="Question3" value="C" /> 
      105. C.</label> 
      106. 酒吧外景</p> 
      107. <p>4. 音樂往事中女主人公喝的酒叫什么名字?<br /> 
      108. <label> 
      109. <input type="radio" name="Question4" value="A" /> 
      110. A.</label> 
      111. 紅粉佳人<br /> 
      112. <label> 
      113. <input type="radio" name="Question4" value="B" /> 
      114. B.</label> 
      115. 七色彩虹<br /> 
      116. <label> 
      117. <input type="radio" name="Question4" value="C" /> 
      118. C.</label> 
      119. 蔚藍海岸</p> 
      120. <p>5.遺忘黯淡中New Vision雜志的封面人物是誰?<br /> 
      121. <label> 
      122. <input type="radio" name="Question5" value="A" /> 
      123. A.</label> 玄斌<br /> 
      124. <label> 
      125. <input type="radio" name="Question5" value="B" /> 
      126. B.</label> Rain<br /> 
      127. <label> 
      128. <input type="radio" name="Question5" value="C" /> 
      129. C.</label> 張東健</p> 
      130. <p>6. 音樂往事中的唱片名字是什么?<br /> 
      131. <label> 
      132. <input type="radio" name="Question6" value="A" /> 
      133. A.</label> 
      134. BEWITCHED<br /> 
      135. <label> 
      136. <input type="radio" name="Question6" value="B" /> 
      137. B.</label> 
      138. WONDERFUL<br /> 
      139. <label> 
      140. <input type="radio" name="Question6" value="C" /> 
      141. C.</label> 
      142. BEAUTIFUL</p> 
      143. <p>7. 音樂往事中的酒吧墻壁上寫著什么?<br /> 
      144. <label> 
      145. <input type="radio" name="Question7" value="A" /> 
      146. A.</label> 
      147. Love is beautiful<br /> 
      148. <label><input type="radio" name="Question7" value="B" /> 
      149. B.</label> 
      150. Truth is beautiful<br /> 
      151. <label><input type="radio" name="Question7" value="C" /> 
      152. C.</label> 
      153. Smile is beautiful</p> 
      154. <p>8. 音樂往事中的吧臺上擺放著什么?<br /> 
      155. <label><input type="radio" name="Question8" value="A" /> 
      156. A.</label> 
      157. 留聲機<br /> 
      158. <label><input type="radio" name="Question8" value="B" /> 
      159. B.</label> 
      160. 收音機<br /> 
      161. <label><input type="radio" name="Question8" value="C" /> 
      162. C.</label> 
      163. 黑膠唱片</p> 
      164. <p>9. 音樂往事中男主人公的喜好是?<br /> 
      165. <label><input type="radio" name="Question9" value="A" /> 
      166. A.</label> 
      167. 電影<br /> 
      168. <label><input type="radio" name="Question9" value="B" /> 
      169. B.</label> 
      170. 攝影<br /> 
      171. <label><input type="radio" name="Question9" value="C" /> 
      172. C.</label> 
      173. 煙草和音樂</p> 
      174. <p>10.凝固精彩中的主人公愛好什么?<br /> 
      175. <label><input type="radio" name="Question10" value="A" /> 
      176. A.</label> 
      177. 旅游<br /> 
      178. <label><input type="radio" name="Question10" value="B" /> 
      179. B.</label> 
      180. 攝影<br /> 
      181. <label><input type="radio" name="Question10" value="C" /> 
      182. C.</label> 
      183. 上網</p> 
      184. <p><br /> 
      185. <input type="submit" name="Submit" value="提交" /> 
      186. <br /> 
      187. </p> 
      188. </form> 
      189. </body> 
      190. </html> 

      下面是后臺代碼Test_do.asp,代碼如下:

      1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
      2. <!-- #include file="conn.asp" --> 
      3. <!-- #include file="function.asp" --> 
      4. <
      5. Response.CacheControl = "no-cache"  
      6. Response.Expires = -1 
      7. Response.ExpiresAbsolute=now()-1 
      8.  
      9. if session("username")="" then 
      10. Response.Write("<script>alert('請登陸后在進行操作!');window.location='login.asp?reURL=Nv_Scene_Test.asp';</script>") 
      11. Response.End() 
      12. end if 
      13.  
      14. '定義選項的最高分即總分 
      15. Const TOTALSCORE = 100 
      16. Const ITEMS = 10 
      17. '定義選項分數 
      18. Dim Result(9) 
      19. '第一題得分標準 
      20. Result(0) = "A|10|_|B|0|_|C|0" 
      21.  
      22. '第二題得分標準 
      23. Result(1) = "A|0|_|B|10|_|C|0" 
      24.  
      25. '第三題得分標準 
      26. Result(2) = "A|10|_|B|0|_|C|0" 
      27.  
      28. '第四題得分標準 
      29. Result(3) = "A|0|_|B|0|_|C|10" 
      30.  
      31. '第五題得分標準 
      32. Result(4) = "A|0|_|B|0|_|C|10" 
      33.  
      34. '第六題得分標準 
      35. Result(5) = "A|10|_|B|0|_|C|0" 
      36.  
      37. '第七題得分標準 
      38. Result(6) = "A|0|_|B|10|_|C|0" 
      39.  
      40. '第八題得分標準 
      41. Result(7) = "A|10|_|B|0|_|C|0" 
      42.  
      43. '第九題得分標準 
      44. Result(8) = "A|0|_|B|0|_|C|10" 
      45.  
      46. '第十題得分標準 
      47. Result(9) = "A|0|_|B|10|_|C|0" 
      48.  
      49. ''第十一題得分標準 
      50. 'Result(10) = "A|0|_|B|0|_|C|10" 
      51. ''第十二題得分標準 
      52. 'Result(11) = "A|0|_|B|10|_|C|0" 
      53. ''第十三題得分標準 
      54. 'Result(12) = "A|10|_|B|0|_|C|0" 
      55. ''第十四題得分標準 
      56. 'Result(13) = "A|0|_|B|10|_|C|0" 
      57. ''第十五題得分標準 
      58. 'Result(14) = "A|0|_|B|0|_|C|10" 
      59.  
      60.  
      61. If UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST" Then 
      62. Call Chk_Post() 
      63. Dim i,total,selItem,summary,strDes,strOut  
      64. total = 0 
      65.  
      66.  
      67. For i = 0 To (ITEMS-1) 
      68. selVal = Trim(Request.Form("Question"&i+1)) 
      69. arrItem = Split(Result(i),"|_|") 
      70.  
      71. For j = 0 To Ubound(arrItem) 
      72.  
      73. If selVal = Split(arrItem(j),"|")(0) Then 
      74.  
      75. totaltotal = total + CInt(Split(arrItem(j),"|")(1)) 
      76. selItemselItem = selItem &"<li>Question"&i+1&":"&selVal&"</li>"&vbCrLf 
      77. End If 
      78. Next 
      79. Next 
      80. summary = FormatPercent(total/TOTALSCORE) 
      81.  
      82. If (total/TOTALSCORE)>=0.6 Then 
      83. strDes = "正確率 "&summary&"<br>您已經順利通過吧" 
      84. Else 
      85. strDes = "正確率 "&summary&"<br>很遺憾,您正確率還沒有達到60%。請再來試試吧!<br><a href=Test.asp'>回在線問答頁>></a>
      86. End If 
      87.  
      88. strOut = "You have Selected these items below:<br>"&selItem&"<br>Total:"&total&"<br>您的正確率為:"&summary 
      89. strOutstrOut = strOut &"<br>"&strDes 
      90.  
      91. str_sql = "SELECT Count(1) FROM UserInfo WHERE MemberId='"&Session("Id")&"'" 
      92. rowCount = DataConn.execute(str_sql)(0) 
      93.  
      94. If rowCount > 0 Then'如果存在就更新個人信息 
      95. str_sql = "UPDATE UserInfo " 
      96. str_sqlstr_sql = str_sql &" SET Result = '"&FormatNumber(total/TOTALSCORE,2)&"'
      97. str_sqlstr_sql = str_sql &" ,ip = '"&Get_UserIp()&"'
      98. str_sqlstr_sql = str_sql &" ,AddTime = getdate()" 
      99. str_sqlstr_sql = str_sql &" WHERE MemberID'"&Session("Id")&"'
      100. Else 
      101. str_sql = "INSERT INTO UserInfo( Result,MemberId,MemberName,ip) " 
      102. str_sqlstr_sql = str_sql &" VALUES('"& FormatNumber(total/TOTALSCORE,2)&"','"&Session("Id")&"','"&Session("Username")&"','"&Get_UserIp()&"')" 
      103. End If 
      104. DataConn.execute(str_sql) 
      105. End If 
      106.  
      107.  
      108. %> 
      109. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      110. <html xmlns="http://www.w3.org/1999/xhtml"> 
      111. <head> 
      112. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
      113. <title>在線問答測試結果</title> 
      114. <style type="text/css"> 
      115. <!-- 
      116. body { 
      117. font-size: 12px; 
      118. color: #0066FF; 
      119. input { 
      120. border: 1px solid #FFFFFF; 
      121. background-color: #EEEEEE; 
      122. left: 1px; 
      123. top: 1px; 
      124. right: 1px; 
      125. bottom: 1px; 
      126. clip: rect(10px,10px,10px,10px); 
      127. margin: 1px; 
      128. padding: 1px; 
      129.  
      130. --> 
      131. </style> 
      132. </head> 
      133.  
      134. <body> 
      135. <%Response.Write(strOut)%> 
      136. </body> 
      137. </html> 

      分享:ASP Error對象的技巧
      在VBScript中,有一個On Error Resume Next語句,它使腳本解釋器忽略運行期錯誤并繼續腳本代碼的執行。接著該腳本可以檢查Err.Number屬性的值,判別是否出現了錯誤。如果出現錯誤,返回一個非零值。在ASP 3.0中,也可以使用On Error Goto 0“轉回到”缺省的

      來源:模板無憂//所屬分類:ASP教程/更新時間:2012-06-11
      相關ASP教程