ASP Contents 集合
Contents 集合包含着通过脚本命令添加到 application/session 的所有项目。
提示:要从 Contents 集合中删除项目,请使用 Remove 和 RemoveAll 方法。
语法
1 | <div> Application.Contents(Key)<br><br> Session.Contents(Key) </div>
|
针对 Application 对象的实例
实例 1
请注意,name 和 objtest 都会被追加到 Contents 集合中:
1 | <div> <% <br> Application( "name" )= "W3CSchool" <br> Set Application( "objtest" )=Server.CreateObject( "ADODB.Connection" )<br> %> </div>
|
实例 2
遍历 Contents 集合:
1 | <div> <%<br> for each x in Application.Contents<br> Response.Write(x & "=" & Application.Contents(x) & "<br>" )<br> next<br> %><br><br> 或者:<br><br> <%<br> For i=1 to Application.Contents. Count <br> Response.Write(i & "=" & Application.Contents(i) & "<br>" )<br> Next<br> %> </div>
|
实例 3
1 | <div> <%<br> Application( "date" )= "2001/05/05" <br> Application( "author" )= "W3CSchool" <br><br> for each x in Application.Contents<br> Response.Write(x & "=" & Application.Contents(x) & "<br>" )<br> next<br> %><br><br> 输出:<br><br> date =2001/05/05<br> author=W3CSchool </div>
|
针对 Session 对象的实例
实例 1
请注意,name 和 objtest 都会被追加到 Contents 集合中:
1 | <div> <%<br> Session( "name" )= "Hege" <br> Set Session( "objtest" )=Server.CreateObject( "ADODB.Connection" )<br> %> </div>
|
实例 2
遍历 Contents 集合:
1 | <div> <%<br> for each x in Session.Contents<br> Response.Write(x & "=" & Session.Contents(x) & "<br>" )<br> next<br> %><br><br> 或者:<br><br> <%<br> For i=1 to Session.Contents. Count <br> Response.Write(i & "=" & Session.Contents(i) & "<br>" )<br> Next<br> %> </div>
|
实例 3
1 | <div> <%<br> Session( "name" )= "Hege" <br> Session( "date" )= "2001/05/05" <br><br> for each x in Session.Contents<br> Response.Write(x & "=" & Session.Contents(x) & "<br>" )<br> next<br> %><br><br> 输出:<br><br> name=Hege<br> date =2001/05/05 </div>
|