แนะนำ: ASP ใช้ XML เพื่อจัดทำโฟลเดอร์ที่ระบุและอัปโหลดไปยังเว็บไดเรกทอรี '================================' ไฟล์ 1 'Pack.asp' เปลี่ยน CPathName ตัวแปรนี้ 'จะสร้างไฟล์ data.xml ในไดเรกทอรีไดเรกทอรีปัจจุบัน ไฟล์ '================================== % ตัวเลือก Explic Explic
รหัสตัวอย่างสำหรับคำถามและคำตอบออนไลน์ของ ASP คือไฟล์ HTML ซึ่งเป็น test.asp และรหัสมีดังนี้:
- <%@language = vbscriptCodePage = 936%>
- -
- ifsession (ชื่อผู้ใช้) = จากนั้น
- 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>
- -
- ร่างกาย{}{
- ขนาดตัวอักษร: 12px;
- สี:#0066ff;
- -
- ป้อนข้อมูล{}{
- ชายแดน: 1pxsolid#ffffff;
- พื้นหลังสี: #eeeeee;
- ซ้าย: 1px;
- ด้านบน: 1px;
- ขวา: 1px;
- ด้านล่าง: 1px;
- คลิป: rect (10px, 10px, 10px, 10px);
- มาร์จิ้น: 1px;
- ช่องว่าง: 1px;
- -
- -
- </style>
- </head>
- <scriptLanguage = JavaScript>
- -
- functionchkform ()
- -
- vare = document.frm;
- Varit, Flag, I;
- ธง = เท็จ;
- สำหรับ (i = 1; i <= 10; i ++)
- -
- variant = eval (e.question+i);
- VariantLen = Eval (E.Question+I+.length);
- สำหรับ (varj = 0; j <itlen; j ++)
- -
- varitchk = eval (e.question+i+[+j+] ตรวจสอบ);
- ถ้า (itchk)
- -
- ธง = จริง;
- หยุดพัก;
- -
- if (! itchk && j == itlen-1)
- -
- ธง = เท็จ;
- หยุดพัก;
- -
- -
- ถ้า (! ธง)
- -
- การแจ้งเตือน (โปรดเลือกคำตอบสำหรับคำถาม +i +);
- returnfalse;
- -
- -
- ถ้า (! ธง)
- -
- การแจ้งเตือน (โปรดเลือกคำตอบสำหรับคำถาม +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. </lable>
- lan <br/>
- <label>
- <inputType = radioname = question1Value = b/>
- b. </lable>
- Jenny <br/> <baild>
- <inputType = radioname = question1Value = c/>
- c. </lable> Lucy </p>
- <p> 2. ชื่อของบาร์ในอดีตเพลงคืออะไร? <br/>
- <label>
- <inputType = radioname = question2Value = a/>
- a. </lable>
- ลืมไปแล้ว <br/>
- <label>
- <inputType = radioname = question2Value = b/>
- b. </lable>
- NV <br/>
- <label>
- <inputType = radioname = question2Value = c/>
- c. </lable>
- เหมือนเงา </p>
- <p> 3. มีรูปถ่ายอะไรบ้างบนผนังของภาพถ่ายที่ถูกลืม? <br/>
- <label>
- <inputType = radioname = question3Value = a/>
- a. </lable>
- นางเอกในอดีต <br/>
- <label>
- <inputType = radioname = question3Value = b/>
- b. </lable>
- ทิวทัศน์ริมทะเล <br/>
- <label>
- <inputType = radioname = question3Value = c/>
- c. </lable>
- บาร์ด้านนอก </p>
- <p> 4. ชื่อไวน์ที่นางเอกเครื่องดื่มในเพลงที่ผ่านมาคืออะไร? <br/>
- <label>
- <inputType = radioname = question4Value = a/>
- a. </lable>
- ความงามสีชมพูแดง <br/>
- <label>
- <inputType = radioname = question4Value = b/>
- b. </lable>
- รุ้งเจ็ดสี <br/>
- <label>
- <inputType = radioname = question4Value = c/>
- c. </lable>
- Costa del Azure </p>
- <p> 5. ใครเป็นตัวละครปกของนิตยสาร Newvision ในการหลงลืม? <br/>
- <label>
- <inputType = radioname = quustion5Value = a/>
- a. </lable> Xuanbin <br/>
- <label>
- <inputType = radioname = quustion5Value = b/>
- b. </lable> ฝน <br/>
- <label>
- <inputType = radioname = quustion5Value = c/>
- c. </lable> Zhang Dongjian </p>
- <p> 6. ชื่อของบันทึกในอดีตของเพลงคืออะไร? <br/>
- <label>
- <inputType = radioname = question6Value = a/>
- a. </lable>
- Bewitched <br/>
- <label>
- <inputType = radioname = question6Value = b/>
- b. </lable>
- ยอดเยี่ยม <br/>
- <label>
- <inputType = radioname = question6Value = c/>
- c. </lable>
- สวยงาม </p>
- <p> 7. มีอะไรเขียนบนผนังบาร์ในอดีตของดนตรี? <br/>
- <label>
- <inputType = radioname = question7Value = a/>
- a. </lable>
- loveisbeautiful <br/>
- <label> <putType = radioname = question7Value = b/>
- b. </lable>
- ความจริงที่สวยงาม <br/>
- <label> <putType = radioname = question7Value = c/>
- c. </lable>
- Smileisbeautiful </p>
- <p> 8. วางอะไรไว้ในบาร์ในอดีตของดนตรี? <br/>
- <label> <putType = radioname = question8Value = a/>
- a. </lable>
- gramophone <br/>
- <label> <putType = radioname = question8Value = b/>
- b. </lable>
- วิทยุ <br/>
- <label> <putType = radioname = question8Value = c/>
- c. </lable>
- บันทึกไวนิล </p>
- <p> 9. ความชอบของตัวเอกชายในเพลงที่ผ่านมาคืออะไร? <br/>
- <label> <putType = radioname = quustion9Value = a/>
- a. </lable>
- ภาพยนตร์ <br/>
- <label> <putType = radioname = quustion9Value = b/>
- b. </lable>
- การถ่ายภาพ <br/>
- <label> <putType = radioname = quustion9Value = c/>
- c. </lable>
- ยาสูบและเพลง </p>
- <p> 10. งานอดิเรกของตัวเอกในคูลดาวน์และความมหัศจรรย์คืออะไร? <br/>
- <label> <putType = radioname = question10Value = a/>
- a. </lable>
- เดินทาง <br/>
- <label> <putType = radioname = question10Value = b/>
- b. </lable>
- การถ่ายภาพ <br/>
- <label> <putType = radioname = question10Value = c/>
- c. </lable>
- ออนไลน์ </p>
- <p> <br/>
- <inputType = submitName = submentValue = submit/ subment/
- <br/>
- </p>
- </form>
- </body>
- </html>
ต่อไปนี้เป็นรหัสพื้นหลัง test_do.asp รหัสมีดังนี้:
- <%@language = vbscriptCodePage = 936%>
- <!-#includit file = conn.asp->
- <!-#includefile = function.asp->
- -
- Response.cacheControl = ไม่มีแคช
- Response.expires = -1
- Response.expiresabsolute = Now ()-1
- ifsession (ชื่อผู้ใช้) = จากนั้น
- Response.write (<script> Alert ('โปรดเข้าสู่ระบบจากนั้นใช้งาน!'); window.location = 'login.asp? reurl = nv_scene_test.asp'; </script>)
- Response.end ()
- endif
- 'คะแนนสูงสุดสำหรับตัวเลือกคำจำกัดความคือคะแนนรวม
- consttotalscore = 100
- constitems = 10
- 'กำหนดคะแนนตัวเลือก
- dimresult (9)
- 'เกณฑ์การให้คะแนนสำหรับคำถามแรก
- ผลลัพธ์ (0) = a | 10 | _ | b | 0 | _ | c | 0
- 'เกณฑ์คะแนนสำหรับคำถามที่ 2
- ผลลัพธ์ (1) = a | 0 | _ | b | 10 | _ | c | 0
- 'เกณฑ์คะแนนคำถามที่สาม
- ผลลัพธ์ (2) = a | 10 | _ | b | 0 | _ | c | 0
- 'คำถาม 4 คะแนนมาตรฐาน
- ผลลัพธ์ (3) = a | 0 | _ | b | 0 | _ | c | 10
- 'คำถาม 5 คะแนนมาตรฐาน
- ผลลัพธ์ (4) = a | 0 | _ | b | 0 | _ | c | 10
- 'คำถาม 6 เกณฑ์คะแนน
- ผลลัพธ์ (5) = a | 10 | _ | b | 0 | _ | c | 0
- 'คำถามที่ 7 เกณฑ์คะแนน
- ผลลัพธ์ (6) = a | 0 | _ | b | 10 | _ | c | 0
- 'คำถามที่ 8 เกณฑ์คะแนน
- ผลลัพธ์ (7) = a | 10 | _ | b | 0 | _ | c | 0
- 'คำถามที่ 9 เกณฑ์คะแนน
- ผลลัพธ์ (8) = a | 0 | _ | b | 0 | _ | c | 10
- 'คำถามที่ 10 เกณฑ์คะแนน
- ผลลัพธ์ (9) = a | 0 | _ | b | 10 | _ | c | 0
- '' คำถามที่ 11 เกณฑ์คะแนน
- 'ผลลัพธ์ (10) = a | 0 | _ | b | 0 | _ | c | 10
- -
- '' คำถาม 12 เกณฑ์คะแนน
- 'ผลลัพธ์ (11) = a | 0 | _ | b | 10 | _ | c | 0
- -
- '' คำถาม 13 เกณฑ์คะแนน
- 'ผลลัพธ์ (12) = a | 10 | _ | b | 0 | _ | c | 0
- -
- '' คำถามที่ 14 เกณฑ์การให้คะแนน
- 'ผลลัพธ์ (13) = a | 0 | _ | b | 10 | _ | c | 0
- -
- '' คำถามที่ 15 เกณฑ์คะแนน
- 'ผลลัพธ์ (14) = a | 0 | _ | b | 0 | _ | c | 10
- ifucase (request.serverVariables (request_method)) = postthen
- callchk_post ()
- dimi, total, selitem, สรุป, strdes, strout
- ทั้งหมด = 0
- fori = 0to (รายการ -1)
- selval = trim (request.form (คำถาม & i+1))
- arritem = split (ผลลัพธ์ (i), | _ |)
- forj = 0toubound (arritem)
- ifselval = split (arritem (j), |) (0) จากนั้น
- TotalTotal = Total+Cint (แยก (arritem (j), |) (1))
- selitemselitem = selitem & <li> คำถาม & i+1 &: & selval & </li> & vbcrlf
- endif
- ต่อไป
- ต่อไป
- summary = formatpercent (total/totalscore)
- if (total/totalscore)> = 0.6 จากนั้น
- strdes = ความสม่ำเสมอและสรุป & <br> คุณผ่านไปแล้วสำเร็จแล้ว
- อื่น
- strdes = ผลลัพธ์ & สรุป & <br> น่าเศร้าอัตราความแม่นยำของคุณยังไม่ถึง 60% โปรดลองอีกครั้ง! <br> <ahref = test.asp '> กลับไปที่หน้าถาม & ตอบออนไลน์ >> </a>
- endif
- strout = youhaveselectedtheseitemsbelow: <br> & selitem & <br> ทั้งหมด: & ทั้งหมด & <br> ความแม่นยำของคุณคือ: & สรุป
- stroutstrout = strout & <br> & strdes
- str_sql = selectcount (1) fromuserinfowherememberid = '& เซสชัน (id) &'
- rowcount = dataconn.execute (str_sql) (0)
- ifrowcount> 0 แล้วข้อมูลส่วนบุคคลหากมีอยู่จริง
- str_sql = updateUserInfo
- str_sqlstr_sql = str_sql & setResult = '& formatNumber (ทั้งหมด/totalsCore, 2) &'
- str_sqlstr_sql = str_sql &, ip = '& get_userip () &'
- str_sqlstr_sql = str_sql &, addTime = getDate ()
- str_sqlstr_sql = str_sql & wherememberid = '& เซสชัน (id) &'
- อื่น
- str_sql = insertintouserInfo (ผลลัพธ์, memberId, memberName, IP)
- str_sqlstr_sql = str_sql & ค่า ('& formatNumber (ทั้งหมด/totalsCore, 2) &', '& เซสชัน (id) &', '& เซสชัน (ชื่อผู้ใช้) &', '& 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>
- -
- ร่างกาย{
- ขนาดตัวอักษร: 12px;
- สี:#0066ff;
- -
- ป้อนข้อมูล{
- ชายแดน: 1pxsolid#ffffff;
- พื้นหลังสี: #eeeeee;
- ซ้าย: 1px;
- ด้านบน: 1px;
- ขวา: 1px;
- ด้านล่าง: 1px;
- คลิป: rect (10px, 10px, 10px, 10px);
- มาร์จิ้น: 1px;
- ช่องว่าง: 1px;
- -
- -
- </style>
- </head>
- <body>
- <%response.write (strout)%>
- </body>
- </html>
แบ่งปัน: เคล็ดลับสำหรับวัตถุข้อผิดพลาด ASP ใน VBScript มีข้อผิดพลาดในการดำเนินการต่อคำสั่งถัดไปที่ทำให้สคริปต์ล่ามเพื่อละเว้นข้อผิดพลาดรันไทม์และดำเนินการต่อของรหัสสคริปต์ต่อไป จากนั้นสคริปต์สามารถตรวจสอบค่าของคุณสมบัติ err.number เพื่อตรวจสอบว่าเกิดข้อผิดพลาดหรือไม่ หากเกิดข้อผิดพลาดค่าที่ไม่เป็นศูนย์จะถูกส่งคืน ใน ASP 3.0 คุณยังสามารถใช้ข้อผิดพลาด GOTO 0 ถึง "กลับไปที่" ค่าเริ่มต้น