Recommended: ASP uses XML to package the specified folder and upload it to the WEB directory, unpack it by itself '============================== 'File 1 'Pack.asp 'Change Cpathname This variable' will generate a DATA.XML file in the current directory' Upload DATA.XML and file 2 (install.asp) to the WEB root directory'Run install.asp unpacking' Manually delete the above two files'=============================== % Option Explic
The example code for ASP online Q&A is the HTML file, which is Test.asp, and the code is as follows:
- <%@LANGUAGE=VBSCRIPTCODEPAGE=936%>
- <%
- ifsession(username)=then
- Response.Write(<script>alert('Please log in and then perform operations!');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>Scenario Q&A</title>
- <styletype=text/css>
- <!--
- body{}{
- font-size:12px;
- color:#0066FF;
- }
- input{}{
- border:1pxsolid#FFFFFF;
- background-color:#EEEEE;
- 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++)
- {
- variant=eval(e.Question+i);
- variantLen=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 (please select the answer to question +i+);
- returnfalse;
- }
- }
- if(!flag)
- {
- alert (please select the answer to question +i+);
- eval(e.Question+i+.focus());
- returnfalse;
- }
- returntrue;
- }
- -->
- </script>
- <body>
- <div><strong>Scenario Q&A</strong></div>
- <formname=frmaction=Test_do.aspmethod=postonsubmit=return(chkForm());>
- <p><br/>
- 1. What is the name of the heroine in Forgotten and Down? <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.What is the name of the bar in the past of music? <br/>
- <label>
- <inputtype=radioname=Question2value=A/>
- A.</label>
- Forgotten<br/>
- <label>
- <inputtype=radioname=Question2value=B/>
- B.</label>
- NV<br/>
- <label>
- <inputtype=radioname=Question2value=C/>
- C.</label>
- Like a shadow</p>
- <p>3. What photos are there on the wall of the forgotten photo? <br/>
- <label>
- <inputtype=radioname=Question3value=A/>
- A.</label>
- The heroine of the past<br/>
- <label>
- <inputtype=radioname=Question3value=B/>
- B.</label>
- The scenery by the sea<br/>
- <label>
- <inputtype=radioname=Question3value=C/>
- C.</label>
- Bar Exterior</p>
- <p>4.What is the name of the wine the heroine drinks in the past music? <br/>
- <label>
- <inputtype=radioname=Question4value=A/>
- A.</label>
- Red pink beauty<br/>
- <label>
- <inputtype=radioname=Question4value=B/>
- B.</label>
- Seven-colored rainbow<br/>
- <label>
- <inputtype=radioname=Question4value=C/>
- C.</label>
- Costa del Azure</p>
- <p>5.Who is the cover character of NewVision magazine in the Forgetfulness? <br/>
- <label>
- <inputtype=radioname=Question5value=A/>
- A.</label>Xuanbin<br/>
- <label>
- <inputtype=radioname=Question5value=B/>
- B.</label>Rain<br/>
- <label>
- <inputtype=radioname=Question5value=C/>
- C.</label>Zhang Dongjian</p>
- <p>6.What is the name of the record in the past of music? <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.What is written on the wall of the bar in the past of music? <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.What is placed on the bar in the past of music? <br/>
- <label><inputtype=radioname=Question8value=A/>
- A.</label>
- Gramophone<br/>
- <label><inputtype=radioname=Question8value=B/>
- B.</label>
- Radio<br/>
- <label><inputtype=radioname=Question8value=C/>
- C.</label>
- Vinyl Records</p>
- <p>9.What is the male protagonist’s preference in the past music? <br/>
- <label><inputtype=radioname=Question9value=A/>
- A.</label>
- Movie<br/>
- <label><inputtype=radioname=Question9value=B/>
- B.</label>
- Photography<br/>
- <label><inputtype=radioname=Question9value=C/>
- C.</label>
- Tobacco and music</p>
- <p>10. What is the protagonist's hobby in the cooldown and wonderfulness? <br/>
- <label><inputtype=radioname=Question10value=A/>
- A.</label>
- Travel<br/>
- <label><inputtype=radioname=Question10value=B/>
- B.</label>
- Photography<br/>
- <label><inputtype=radioname=Question10value=C/>
- C.</label>
- Go online</p>
- <p><br/>
- <inputtype=submitname=Submitvalue=submit/
- <br/>
- </p>
- </form>
- </body>
- </html>
The following is the background code Test_do.asp, the code is as follows:
- <%@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('Please log in and then operate it!');window.location='login.asp?reURL=Nv_Scene_Test.asp';</script>)
- Response.End()
- endif
- 'The highest score for the definition option is the total score
- ConstTOTALSCORE=100
- ConstITEMS=10
- 'Define option score
- DimResult(9)
- 'The scoring criteria for the first question
- Result(0)=A|10|_|B|0|_|C|0
- 'Score criteria for question 2
- Result(1)=A|0|_|B|10|_|C|0
- 'The third question score criteria
- Result(2)=A|10|_|B|0|_|C|0
- 'Question 4 Score Standard
- Result(3)=A|0|_|B|0|_|C|10
- 'Question 5 Score Standard
- Result(4)=A|0|_|B|0|_|C|10
- 'Question 6 Score criteria
- Result(5)=A|10|_|B|0|_|C|0
- 'Question 7 Score criteria
- Result(6)=A|0|_|B|10|_|C|0
- 'Question 8 Score criteria
- Result(7)=A|10|_|B|0|_|C|0
- 'Question 9 Score criteria
- Result(8)=A|0|_|B|0|_|C|10
- 'Question 10th Score Criteria
- Result(9)=A|0|_|B|10|_|C|0
- ''Question 11 Score Criteria
- 'Result(10)=A|0|_|B|0|_|C|10
- '
- ''Question 12 Score criteria
- 'Result(11)=A|0|_|B|10|_|C|0
- '
- ''Question 13 Score criteria
- 'Result(12)=A|10|_|B|0|_|C|0
- '
- ''Question 14th Scoring Criteria
- 'Result(13)=A|0|_|B|10|_|C|0
- '
- ''Question 15th Score Criteria
- '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=Regularity&summary&<br>You have passed it successfully
- Else
- strDes=Result&Summary&<br>Sadly, your accuracy rate has not reached 60%. Please try again! <br><ahref=Test.asp'>Return to online Q&A page>></a>
- EndIf
- strOut=YouhaveSelectedtheseitemsbelow:<br>&selItem&<br>Total:&total&<br>Your accuracy is:&summary
- strOutstrOut=strOut&<br>&strDes
- str_sql=SELECTCount(1)FROMUserInfoWHEREMemberId='&Session(Id)&'
- rowCount=DataConn.execute(str_sql)(0)
- IfrowCount>0Then'Update personal information if it exists
- 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>Online Q&A test results</title>
- <styletype=text/css>
- <!--
- body{
- font-size:12px;
- color:#0066FF;
- }
- input{
- border:1pxsolid#FFFFFF;
- background-color:#EEEEE;
- 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>
Share: Tips for ASP Error Objects In VBScript, there is an On Error Resume Next statement that causes the script interpreter to ignore runtime errors and continue execution of the script code. Then the script can check the value of the Err.Number property to determine whether an error occurred. If an error occurs, a non-zero value is returned. In ASP 3.0, you can also use On Error Goto 0 to "turn back to" the default