首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>网络编程>ASP教程>资讯:ASP所有的Session变量获取实现代码

ASP所有的Session变量获取实现代码

www.jz123.cn  2010-01-07   来源:   中国建站    责任编辑(袁袁)    我要投递新闻

  在程序调试中,有时候需要知道有多少Session变量在使用,她们的值如何?由于Session对象提供一个称为Contents的集合(Collection),我们可以通过For...Each循环来达到目标

Dim strName, iLoop
For Each strName in Session.Contents
Response.Write strName & " - " & Session.Contents(strName)& "[BR]"
Next

  一般情况下,上面的代码可以工作得很好。但当Session变量是一个对象或者数组时,打印的结果就不正确了。 这样我们修改代码如下:

'首先看看有多少Session变量在使用?
Response.Write "There are " & Session.Contents.Count & _
" Session variables<P>"
Dim strName, iLoop
'使用For Each循环察看Session.Contents
'如果Session变量是一个数组?
If IsArray(Session(strName)) then
'循环打印数组的每一个元素
For iLoop = LBound(Session(strName)) to UBound(Session(strName))
Response.Write strName & "(" & iLoop & ") - " & _
Session(strName)(iLoop) & "<BR>"
Next
Else
'其他情况,就简单打印变量的值
Response.Write strName & " - " & Session.Contents(strName) & "<BR>"
End If
Next

  '首先看看有多少Session变量在使用?

  Response.Write "There are " & Session.Contents.Count & _

  " Session variables<P>"

  Dim strName, iLoop

  '使用For Each循环察看Session.Contents

  '如果Session变量是一个数组?

  If IsArray(Session(strName)) then

  '循环打印数组的每一个元素

  For iLoop = LBound(Session(strName)) to UBound(Session(strName))

  Response.Write strName & "(" & iLoop & ") - " & _

  Session(strName)(iLoop) & "<BR>"

  Next

  Else

  '其他情况,就简单打印变量的值

  Response.Write strName & " - " & Session.Contents(strName) & "<BR>"

  End If

  Next

<%@ ENABLESESSIONSTATE=True %>

  而其他页面设置为:

<%@ ENABLESESSIONSTATE=False %>


上一篇:asp 网站静态化函数代码html 下一篇:一些常用的正则表达式大全

评论总数:0 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图