当前位置: 首页 > 图文教程 > 网络编程 > ASP > session变量中的数组如何引用

ASP
Adodb.Command 平时很少注意到的一个参数
Asp.Net控件加载错误的解决方法
远程连接access数据库的方法
创建具有JScript的HTML的XMLHTTP
在Asp中如何快速优化分页的技巧
用VB生成DLL封装ASP代码,连接数据库
RS.OPEN SQL,CONN,A,B 全接触
利用adodb.stream直接下载任何后缀的文件(防盗链)
用ASP编程控制在IIS建立Web站点的程序代码
使用VBScript操作Html复选框(CheckBox)控件
把文章内容中涉及到的图片自动保存到本地服务器
两个不同数据库表的分页显示解决方案
使用组件封装数据库操作(一)
使用组件封装数据库操作(二)
如何在pb中创建COM组件,并在asp中调用并返回结果集?
用ASP和Microsoft.XMLDOM分析远程XML文件
浅谈无刷新取得远程数据技术
将ASP纪录集输出成n列的的表格形式显示的方法
在ASP中通过oo4o连接Oracle数据库的例子
Server Application Error详细解决办法

ASP 中的 session变量中的数组如何引用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 45 ::
收藏到网摘: n/a

  If you store an array in a Session object, you should not attempt to alter the elements of the stored array directly. For example, the following script will not work:

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

This is because the Session object is implemented as a collection. The array element StoredArray(3) does not receive the new value. Instead, the value is indexed into the collection, overwriting any information stored at that location.

It is strongly recommended that if you store an array in the Session object, you retrieve a copy of the array before retrieving or changing any of the elements of the array. When you are done with the array, you should store the array in the Session object again so that any changes you made are saved. This is demonstrated in the following example:

---file1.asp---
<%
'Creating and initializing the array
Dim MyArray()
Redim MyArray(5)
MyArray(0) = "hello"
MyArray(1) = "some other string"

'Storing the array in the Session object.
Session("StoredArray") = MyArray

Response.Redirect("file2.asp")
%>

---file2.asp---
<%
'Retrieving the array from the Session Object
'and modifying its second element.
LocalArray = Session("StoredArray")
LocalArray(1) = " there"

'Printing out the string "hello there."
Response.Write(LocalArray(0)&LocalArray(1))

'Re-storing the array in the Session object.
'This overwrites the values in StoredArray with the new values.
Session("StoredArray") = LocalArray
%>