ASP Contents 集合

Contents 集合包含着通过脚本命令添加到 application/session 的所有项目。

提示:要从 Contents 集合中删除项目,请使用 RemoveRemoveAll 方法。

语法

  1. Application.Contents(Key)
  2. Session.Contents(Key)
参数描述
key必需。要取回的项目的名称。

针对 Application 对象的实例

实例 1

请注意,nameobjtest 都会被追加到 Contents 集合中:

  1. <%
  2. Application("name")="RUNOOB"
  3. Set Application("objtest")=Server.CreateObject("ADODB.Connection")
  4. %>
实例 2

遍历 Contents 集合:

  1. <%
  2. for each x in Application.Contents
  3. Response.Write(x & "=" & Application.Contents(x) & "<br>")
  4. next
  5. %>

或者:

  1. <%
  2. For i=1 to Application.Contents.Count
  3. Response.Write(i & "=" & Application.Contents(i) & "<br>")
  4. Next
  5. %>
实例 3
  1. <%
  2. Application("date")="2022/05/05"
  3. Application("author")="cankaoshouce"
  4. for each x in Application.Contents
  5. Response.Write(x & "=" & Application.Contents(x) & "<br>")
  6. next
  7. %>

输出:

  1. date=2022/05/05
  2. author=cankaoshouce

针对 Session 对象的实例

实例 1

请注意,nameobjtest 都会被追加到 Contents 集合中:

  1. <%
  2. Session("name")="Hege"
  3. Set Session("objtest")=Server.CreateObject("ADODB.Connection")
  4. %>
实例 2

遍历 Contents 集合:

  1. <%
  2. for each x in Session.Contents
  3. Response.Write(x & "=" & Session.Contents(x) & "<br>")
  4. next
  5. %>

或者

  1. <%
  2. For i=1 to Session.Contents.Count
  3. Response.Write(i & "=" & Session.Contents(i) & "<br>")
  4. Next
  5. %>
实例3
  1. <%
  2. Session("name")="Hege"
  3. Session("date")="2022/05/05"
  4. for each x in Session.Contents
  5. Response.Write(x & "=" & Session.Contents(x) & "<br>")
  6. next
  7. %>

输出:

  1. name=Hege
  2. date=2022/05/05

分类导航