ASP Contents 集合
Contents 集合包含著通過腳本命令添加到application/session 的所有項目。
提示:要從Contents集合中刪除項目,請使用Remove和RemoveAll方法。
語法
Application.Contents(Key)
Session.Contents(Key)
Session.Contents(Key)
参数 | 描述 |
---|---|
key | 必需。要取回的项目的名称。 |
針對Application 對象的實例
實例1
請注意,name 和objtest 都會被追加到Contents 集合中:
<%
Application("name")="W3CSchool"
Set Application("objtest")=Server.CreateObject("ADODB.Connection")
%>
Application("name")="W3CSchool"
Set Application("objtest")=Server.CreateObject("ADODB.Connection")
%>
實例2
遍歷Contents 集合:
<%
for each x in Application.Contents
Response.Write(x & "=" & Application.Contents(x) & "<br>")
next
%>
或者:
<%
For i=1 to Application.Contents.Count
Response.Write(i & "=" & Application.Contents(i) & "<br>")
Next
%>
for each x in Application.Contents
Response.Write(x & "=" & Application.Contents(x) & "<br>")
next
%>
或者:
<%
For i=1 to Application.Contents.Count
Response.Write(i & "=" & Application.Contents(i) & "<br>")
Next
%>
實例3
<%
Application("date")="2001/05/05"
Application("author")="W3CSchool"
for each x in Application.Contents
Response.Write(x & "=" & Application.Contents(x) & "<br>")
next
%>
输出:
date=2001/05/05
author=W3CSchool
Application("date")="2001/05/05"
Application("author")="W3CSchool"
for each x in Application.Contents
Response.Write(x & "=" & Application.Contents(x) & "<br>")
next
%>
输出:
date=2001/05/05
author=W3CSchool
針對Session 對象的實例
實例1
請注意,name 和objtest 都會被追加到Contents 集合中:
<%
Session("name")="Hege"
Set Session("objtest")=Server.CreateObject("ADODB.Connection")
%>
Session("name")="Hege"
Set Session("objtest")=Server.CreateObject("ADODB.Connection")
%>
實例2
遍歷Contents 集合:
<%
for each x in Session.Contents
Response.Write(x & "=" & Session.Contents(x) & "<br>")
next
%>
或者:
<%
For i=1 to Session.Contents.Count
Response.Write(i & "=" & Session.Contents(i) & "<br>")
Next
%>
for each x in Session.Contents
Response.Write(x & "=" & Session.Contents(x) & "<br>")
next
%>
或者:
<%
For i=1 to Session.Contents.Count
Response.Write(i & "=" & Session.Contents(i) & "<br>")
Next
%>
實例3
<%
Session("name")="Hege"
Session("date")="2001/05/05"
for each x in Session.Contents
Response.Write(x & "=" & Session.Contents(x) & "<br>")
next
%>
输出:
name=Hege
date=2001/05/05
Session("name")="Hege"
Session("date")="2001/05/05"
for each x in Session.Contents
Response.Write(x & "=" & Session.Contents(x) & "<br>")
next
%>
输出:
name=Hege
date=2001/05/05
完整的Application對象參考手冊