Example of error checking in ASP

Source: Internet
Author: User
Tags servervariables
There is a program that is to add and remove elements from the application collection, as follows:
<%@ Language=vbscript%>
<HTML>
<HEAD>
<title>the Application object</title>
<style type= "Text/css" >
body {font-family:tahoma,arial,sans-serif; font-size:10pt}
INPUT {font-family:tahoma,arial,sans-serif; font-size:9pt}
. heading {font-family:tahoma,arial,sans-serif; font-size:14pt; Font-weight:bold}
. subhead {font-family:tahoma,arial,sans-serif; font-size:12pt; font-weight:bold; padding-bottom:5px}
. cite {font-family:tahoma,arial,sans-serif; font-size:8pt}
</STYLE>
</HEAD>
<body bgcolor= "#FFFFFF" >
<span class= "heading" >the ASP application
<!--------------------------------------------------------------------------->

<% ' Look for a command sent the FORM section buttons
If Len (Request.Form ("Cmdadd")) Then ' use whether length for 0来 judgment
Strvarname = Request.Form ("Txtvarname")
Strvarvalue = Request.Form ("Txtvarvalue")
Application.Lock
Application (strvarname) = Strvarvalue ' Here is an error
Application.UnLock
End If
If Len (Request.Form ("Cmdremovethis")) Then
Strtoremove = Request.Form ("Lstremove")
Application.Lock
Application.Contents.Remove (Strtoremove)
Application.UnLock
End If
If Len (Request.Form ("Cmdremoveall")) Then
Application.Lock
Application.Contents.RemoveAll
Application.UnLock
End If
%>

<p><div class= "subhead" >the application.contents collection</div>
<%
For each objitem in application.contents
If IsObject (application.contents (objitem)) Then
Response.Write "Object Reference: '" & objitem & "' <BR>"
ElseIf IsArray (application.contents (objitem)) Then
Response.Write "Array:" & objitem & "' Contents are:<br>"
Vararray = application.contents (objitem)
' note:the following with a one-dimensional array
For intloop = 0 to UBound (vararray)
Response.Write "Index (" & intloop & ") =" & Vararray (intloop) & "<BR>"
Next
Else
Response.Write "Variable:" "& objitem &" ' = "_
& Application.Contents (objitem) & "<BR>"
End If
Next
%>
<p><div class= "subhead" >the application.staticobjects collection</div>
<%
For each objitem in application.staticobjects
If IsObject (Application.staticobjects (objitem)) Then
Response.Write "<OBJECT> element:id= '" & Objitem & "<BR>"
End If
Next
%>

<!--collect values to execute application methods with-->
<form action= "<% = Request.ServerVariables (" Script_name ")%>" method= "POST" > "Using Request.ServerVariables ( "Script_name") submits the form to itself

<p><div class= "Subhead" >add a value to the application object</div>
<input type= "SUBMIT" name= "Cmdadd" "value=" ">
Application ("
<input type= "TEXT" name= "Txtvarname" size= "" value= "My_new_value" >
") = "
<input type= "TEXT" name= "Txtvarvalue" size= "value=" testing, testing ... ">
"<P>

<p><div class= "Subhead" >remove a value from application object</div>
<input type= "SUBMIT" name= "Cmdremovethis" "value=" ">
Application.Contents.Remove ("
<select name= "Lstremove" size= "1" >
<%
For each objitem in application.contents
Response.Write "<OPTION>" & Objitem & "</OPTION>"
Next
%>
</SELECT> ") <BR>
<input type= "SUBMIT" name= "Cmdremoveall" "value=" ">
Application.Contents.RemoveAll

</FORM>

<p><div class= "subhead" >other application methods</div>
Application.lock<br>
Application.unlock<p>

<!--------------------------------------------------------------------------->



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.