ASP Getting Started Tutorial-saving application information

Source: Internet
Author: User

First, use the Contents collection application information

1. The Contents collection is a collection of variables and objects that are added to the application by all scripting languages. You can use this collection to get a list of variables for a given application scope or to specify a variable as the action object. The Contents collection is the default collection of application objects, so the following two formats are equivalent:

  Application.Contents("变量名")
  Application("变量名")

where "variable name" is the name of the application variable that needs to be manipulated.

2. Instance code (1.asp): Write a simple counter program using the Session object.

Application </title> of <body>
<center><%
Name=request.form ("Visitor")
I=request.form ("Chatno")
If name<> "" Then
If I=0 Then
Application ("Chinese") =application ("Chinese") +1
chat= "Chinese"
ElseIf I=1 Then
Application ("中文版") =application ("中文版") +1
chat= "English"
End If
Response.Write "<center> Welcome <b>" & name & "&LT;/B&GT; you are Coming"
Response.Write "<b>" & Chat & "</b> Discussion area"
If chat= "Chinese" then
Response.Write application.contents ("Chinese") & "Guest. <p> "
Else
Response.Write application.contents ("中文版") & "Guest. <p> "
End If
Response.Write "<a href= ' 4-6-2.asp ' > Return </a></center>"
Response.End
End If
%>
<center>
<form method=post>
<table><tr><td> Name: <td><input type=text name= "Visitor" size=12>
<tr><td> Discussion Area: <td><select name= "Chatno" >
<option value=0> Chinese </option>
<option value=1> English </option>
</select>
<input type=submit value= "OK" >
</table>
</form>
</center>
</body>

Second, use the Application.staticobjects collection to save application information

The Application object's StaticObjects collection contains all of the objects created in the application scope using object tags, which you can use to determine the value of the specified property of an object or to traverse the collection and retrieve all the properties of all static objects.

1, StaticObjects set of syntax format:

Application.StaticObjects(key)

Where the parameter Key specifies the value of the item to retrieve.

2. Create an object with session scope:

In the Global.asa file, you can create an object with an application scope by using the OBJECT tag and setting the scope property to "application". For example:

   <OBJECT RUNAT=”Server" SCOPE="Application" ID=ID PROGID="MSWC.AdRotator"></OBJECT>

4, not in the Application object to store the built-in object. For example, each of the following lines of script will return an error.

    <%
       set Application("varl")=Session
       set Application("var2")=Request
       set Application("var3")=Response
       set Application("var4")=Server
       set Application("var5")=Application
    %>

Storage of arrays using application objects

You can also store an array in the Application object, but do not directly change the elements in the application array. For example, the following script cannot be run.

    <% Application ("StoredArray") (3)="new value" %>

Instance code (2.asp) to create an array

<% @ language="vbscript" %>
<title>Application 数组应用示例 </title><body>
<%
dim poem()                              '创建一个数组
Redim poem(3)                            '为数组分配存储空间
poem(0)="姓名:含笑"                     '为数组进行初始化
poem(1)="性别:女"
poem(2)="E-mail:www@163.com"
Application.Lock                            '锁定Application 对象
Application("StoredArray")=poem               '将数组存储到 Application 对象中
Application.Unlock                         '解除对Application 对象的锁定
Server.Transfer"3.asp"                      '调用另外一个.asp文件
%>
</body>

3.asp Page Number: Copies the application array to a local array and prints it to the guest end, then modifies the value of the local array element and outputs it to the client, and finally stores the local array into the Application object.

<%
'将Application 数组复制给一个本地数组并输出到客记端
LocalArray=Application("StoredArray")
Response.Write "<Div Align=center>"
For Each s in LocalArray
Response.write s & "<br>"
next
Response.write "'修改本地数组元素的值并输出到客户端
LocalArray(0)="姓名:难书"
LocalArray(1)="性别:女"
LocalArray(2)="E-mail:ddddd@163.com"
For each s In LocalArray
Response.write s & "<br>"
next
Response.Write "</div>"
'将本地数组存储到Application对象中
Application.lock
Application("StoredArray")=LocalApplication
Application.Unlock
%>

See the full set of ASP Getting started tutorials

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.