推薦:ASP利用XML打包指定文件夾並上傳到WEB目錄中,自行解包'======================== '文件1 'Pack.asp '更改Cpathname 這一變量'將在當前目錄生成一個DATA.XML文件'將DATA.XML及文件2(install.asp)上傳至WEB根目錄'運行install.asp解包'手動刪除以上兩個文件'======================== % Option Explic
ASP在線問答的實例代碼首先,是HTML文件,為Test.asp,代碼如下:
- <%@LANGUAGE=VBSCRIPTCODEPAGE=936%>
- <%
- ifsession(username)=then
- Response.Write(<script>alert('請登陸後在進行操作!');window.location='login.asp?reURL=Test.asp';</script>)
- Response.End()
- endif
- %>
- <!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
- <htmlxmlns=http://www.w3.org/1999/xhtml>
- <head>
- <metahttp-equiv=Content-Typecontent=text/html;charset=gb2312/>
- <title>情景問答</title>
- <styletype=text/css>
- <!--
- body{}{
- font-size:12px;
- color:#0066FF;
- }
- input{}{
- border:1pxsolid#FFFFFF;
- background-color:#EEEEEE;
- left:1px;
- top:1px;
- right:1px;
- bottom:1px;
- clip:rect(10px,10px,10px,10px);
- margin:1px;
- padding:1px;
- }
- -->
- </style>
- </head>
- <scriptlanguage=javascript>
- <!--
- functionchkForm()
- {
- vare=document.frm;
- varit,flag,i;
- flag=false;
- for(i=1;i<=10;i++)
- {
- varit=eval(e.Question+i);
- varitLen=eval(e.Question+i+.length);
- for(varj=0;j<itLen;j++)
- {
- varitChk=eval(e.Question+i+[+j+].checked);
- if(itChk)
- {
- flag=true;
- break;
- }
- if(!itChk&&j==itLen-1)
- {
- flag=false;
- break;
- }
- }
- if(!flag)
- {
- alert(請選擇第+i+題答案);
- returnfalse;
- }
- }
- if(!flag)
- {
- alert(請選擇第+i+題答案);
- eval(e.Question+i+.focus());
- returnfalse;
- }
- returntrue;
- }
- -->
- </script>
- <body>
- <div><strong>情景問答</strong></div>
- <formname=frmaction=Test_do.aspmethod=postonsubmit=return(chkForm());>
- <p><br/>
- 1.遺忘黯淡中的女主角叫什麼名字? <br/>
- <label>
- <inputtype=radioname=Question1value=A/>
- A.</label>
- Lan<br/>
- <label>
- <inputtype=radioname=Question1value=B/>
- B.</label>
- Jenny<br/><label>
- <inputtype=radioname=Question1value=C/>
- C.</label>Lucy</p>
- <p>2.音樂往事中酒吧的名字是什麼? <br/>
- <label>
- <inputtype=radioname=Question2value=A/>
- A.</label>
- 遺忘<br/>
- <label>
- <inputtype=radioname=Question2value=B/>
- B.</label>
- NV<br/>
- <label>
- <inputtype=radioname=Question2value=C/>
- C.</label>
- 如影隨形</p>
- <p>3.遺忘黯淡中的照片牆上有什麼照片? <br/>
- <label>
- <inputtype=radioname=Question3value=A/>
- A.</label>
- 從前的女主人公<br/>
- <label>
- <inputtype=radioname=Question3value=B/>
- B.</label>
- 海邊的風景<br/>
- <label>
- <inputtype=radioname=Question3value=C/>
- C.</label>
- 酒吧外景</p>
- <p>4.音樂往事中女主人公喝的酒叫什麼名字? <br/>
- <label>
- <inputtype=radioname=Question4value=A/>
- A.</label>
- 紅粉佳人<br/>
- <label>
- <inputtype=radioname=Question4value=B/>
- B.</label>
- 七色彩虹<br/>
- <label>
- <inputtype=radioname=Question4value=C/>
- C.</label>
- 蔚藍海岸</p>
- <p>5.遺忘黯淡中NewVision雜誌的封面人物是誰? <br/>
- <label>
- <inputtype=radioname=Question5value=A/>
- A.</label>玄斌<br/>
- <label>
- <inputtype=radioname=Question5value=B/>
- B.</label>Rain<br/>
- <label>
- <inputtype=radioname=Question5value=C/>
- C.</label>張東健</p>
- <p>6.音樂往事中的唱片名字是什麼? <br/>
- <label>
- <inputtype=radioname=Question6value=A/>
- A.</label>
- BEWITCHED<br/>
- <label>
- <inputtype=radioname=Question6value=B/>
- B.</label>
- WONDERFUL<br/>
- <label>
- <inputtype=radioname=Question6value=C/>
- C.</label>
- BEAUTIFUL</p>
- <p>7.音樂往事中的酒吧牆壁上寫著什麼? <br/>
- <label>
- <inputtype=radioname=Question7value=A/>
- A.</label>
- Loveisbeautiful<br/>
- <label><inputtype=radioname=Question7value=B/>
- B.</label>
- Truthisbeautiful<br/>
- <label><inputtype=radioname=Question7value=C/>
- C.</label>
- Smileisbeautiful</p>
- <p>8.音樂往事中的吧台上擺放著什麼? <br/>
- <label><inputtype=radioname=Question8value=A/>
- A.</label>
- 留聲機<br/>
- <label><inputtype=radioname=Question8value=B/>
- B.</label>
- 收音機<br/>
- <label><inputtype=radioname=Question8value=C/>
- C.</label>
- 黑膠唱片</p>
- <p>9.音樂往事中男主人公的喜好是? <br/>
- <label><inputtype=radioname=Question9value=A/>
- A.</label>
- 電影<br/>
- <label><inputtype=radioname=Question9value=B/>
- B.</label>
- 攝影<br/>
- <label><inputtype=radioname=Question9value=C/>
- C.</label>
- 煙草和音樂</p>
- <p>10.凝固精彩中的主人公愛好什麼? <br/>
- <label><inputtype=radioname=Question10value=A/>
- A.</label>
- 旅遊<br/>
- <label><inputtype=radioname=Question10value=B/>
- B.</label>
- 攝影<br/>
- <label><inputtype=radioname=Question10value=C/>
- C.</label>
- 上網</p>
- <p><br/>
- <inputtype=submitname=Submitvalue=提交/>
- <br/>
- </p>
- </form>
- </body>
- </html>
下面是後台代碼Test_do.asp,代碼如下:
- <%@LANGUAGE=VBSCRIPTCODEPAGE=936%>
- <!--#includefile=conn.asp-->
- <!--#includefile=function.asp-->
- <%
- Response.CacheControl=no-cache
- Response.Expires=-1
- Response.ExpiresAbsolute=now()-1
- ifsession(username)=then
- Response.Write(<script>alert('請登陸後在進行操作!');window.location='login.asp?reURL=Nv_Scene_Test.asp';</script>)
- Response.End()
- endif
- '定義選項的最高分即總分
- ConstTOTALSCORE=100
- ConstITEMS=10
- '定義選項分數
- DimResult(9)
- '第一題得分標準
- Result(0)=A|10|_|B|0|_|C|0
- '第二題得分標準
- Result(1)=A|0|_|B|10|_|C|0
- '第三題得分標準
- Result(2)=A|10|_|B|0|_|C|0
- '第四題得分標準
- Result(3)=A|0|_|B|0|_|C|10
- '第五題得分標準
- Result(4)=A|0|_|B|0|_|C|10
- '第六題得分標準
- Result(5)=A|10|_|B|0|_|C|0
- '第七題得分標準
- Result(6)=A|0|_|B|10|_|C|0
- '第八題得分標準
- Result(7)=A|10|_|B|0|_|C|0
- '第九題得分標準
- Result(8)=A|0|_|B|0|_|C|10
- '第十題得分標準
- Result(9)=A|0|_|B|10|_|C|0
- ''第十一題得分標準
- 'Result(10)=A|0|_|B|0|_|C|10
- '
- ''第十二題得分標準
- 'Result(11)=A|0|_|B|10|_|C|0
- '
- ''第十三題得分標準
- 'Result(12)=A|10|_|B|0|_|C|0
- '
- ''第十四題得分標準
- 'Result(13)=A|0|_|B|10|_|C|0
- '
- ''第十五題得分標準
- 'Result(14)=A|0|_|B|0|_|C|10
- IfUCase(Request.ServerVariables(REQUEST_METHOD))=POSTThen
- CallChk_Post()
- Dimi,total,selItem,summary,strDes,strOut
- total=0
- Fori=0To(ITEMS-1)
- selVal=Trim(Request.Form(Question&i+1))
- arrItem=Split(Result(i),|_|)
- Forj=0ToUbound(arrItem)
- IfselVal=Split(arrItem(j),|)(0)Then
- totaltotal=total+CInt(Split(arrItem(j),|)(1))
- selItemselItem=selItem&<li>Question&i+1&:&selVal&</li>&vbCrLf
- EndIf
- Next
- Next
- summary=FormatPercent(total/TOTALSCORE)
- If(total/TOTALSCORE)>=0.6Then
- strDes=正確率&summary&<br>您已經順利通過吧
- Else
- strDes=正確率&summary&<br>很遺憾,您正確率還沒有達到60%。請再來試試吧! <br><ahref=Test.asp'>回在線問答頁>></a>
- EndIf
- strOut=YouhaveSelectedtheseitemsbelow:<br>&selItem&<br>Total:&total&<br>您的正確率為:&summary
- strOutstrOut=strOut&<br>&strDes
- str_sql=SELECTCount(1)FROMUserInfoWHEREMemberId='&Session(Id)&'
- rowCount=DataConn.execute(str_sql)(0)
- IfrowCount>0Then'如果存在就更新個人信息
- str_sql=UPDATEUserInfo
- str_sqlstr_sql=str_sql&SETResult='&FormatNumber(total/TOTALSCORE,2)&'
- str_sqlstr_sql=str_sql&,ip='&Get_UserIp()&'
- str_sqlstr_sql=str_sql&,AddTime=getdate()
- str_sqlstr_sql=str_sql&WHEREMemberID='&Session(Id)&'
- Else
- str_sql=INSERTINTOUserInfo(Result,MemberId,MemberName,ip)
- str_sqlstr_sql=str_sql&VALUES('&FormatNumber(total/TOTALSCORE,2)&','&Session(Id)&','&Session(Username)&','&Get_UserIp()&')
- EndIf
- DataConn.execute(str_sql)
- EndIf
- %>
- <!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
- <htmlxmlns=http://www.w3.org/1999/xhtml>
- <head>
- <metahttp-equiv=Content-Typecontent=text/html;charset=gb2312/>
- <title>在線問答測試結果</title>
- <styletype=text/css>
- <!--
- body{
- font-size:12px;
- color:#0066FF;
- }
- input{
- border:1pxsolid#FFFFFF;
- background-color:#EEEEEE;
- left:1px;
- top:1px;
- right:1px;
- bottom:1px;
- clip:rect(10px,10px,10px,10px);
- margin:1px;
- padding:1px;
- }
- -->
- </style>
- </head>
- <body>
- <%Response.Write(strOut)%>
- </body>
- </html>
分享:ASP Error對象的技巧在VBScript中,有一個On Error Resume Next語句,它使腳本解釋器忽略運行期錯誤並繼續腳本代碼的執行。接著該腳本可以檢查Err.Number屬性的值,判別是否出現了錯誤。如果出現錯誤,返回一個非零值。在ASP 3.0中,也可以使用On Error Goto 0“轉回到”缺省的