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

ASP
利用cookie收藏网站
显示左边的n个字符(自动识别汉字)函数
怎样经由ADO来压缩Microsoft Access数据库
样设置为使用OLEDB连接我的Access数据库?
纯猝使用VBScript来实现加密
ASP.NET:处理session
输入显示框中循环出现文字
关于密码校验
图片循环显现
怎样传送更多的数据在表单中
对ASP脚本源代码进行加密
判断函数是奇数还是偶数
SQL7的image字段的文件下载到客户端
怎样把数据库结构显示出来的源代码
随机访问Recordset的一条记录
利用http组件实现多引擎搜索功能
String添加trim,ltrim,rtrim
ASP创建EXCHANGE用户的一段代码
测字符串长度函数
如何从ACCESS数据库中读取图形(续)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 31 ::
收藏到网摘: 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
%>