推荐: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“转回到”缺省的