session变量中的数组如何引用

2016-01-29 18:24 2 1 收藏

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

【 tulaoshi.com - ASP 】

  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
%

 

来源:https://www.tulaoshi.com/n/20160129/1505636.html

延伸阅读
C#中数组是引用类型,C#定义整型数组方式是:int [] intArray = {1,2,3};或int [] intArray = new int;而C++中定义整型数组的方式是:int intArray[] = {1,2,3};或int * intArray = new int;C#中的数组可以是一维的也可以是多维的,同样也支持矩阵和参差不齐的数组。注意:定义多维数组(矩阵)的方式是[,,]而定义多维“参差矩阵”的方式是[]...
标签: PHP
  什么是Session呢?Session直接翻译成中文比较困难,一般都译成时域。在计算机专业术语中,Session是指一个终端用户与交互系统进行通信的时间间隔,通常指从注册进入系统到注销退出系统之间所经过的时间。具体到Web中的Session指的就是用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网站所花费的时...
标签: Web开发
写过稍微大型一点 ASP 的人都知道,Session 这个对象真是好用,它可以用来记录使用者私有的资料变量,既安全又方便。但是你真的知道 Session 的运作原理吗?或许了解以后,你就再也不太敢使用这个令人又爱又恨的对象。虽然转而替代之的方法稍嫌麻烦,但在长期考量之下,也就不得不这么做了。 首先来讲讲 Session 的好处,它可以用来记...
标签: Web开发
各位:我现在在JavaScript中定义一个一维数组,然后调用VB编写的DLL对象,在DLL对象给此数组赋值,然后在JavaScript读出已经赋值的数组。请问如何操作。 DLL对象: TestPrj.Test PublicSubTest(strName()AsVariant) strName(0)="MR" strName(1)="zhang"EndSub JavaScript: Scriptlanguage='...
标签: flash教程
在flash中有一个random函数。它可以随机产生出一个0-1之间的数字,我们可以通过这个函数与数组相结合,非常简便地实现对一组对象的穷举。 以下是一个非常简单的实例: temp_array = new Array(); for(i = 0;i<100;i++){    temp_array[i]=i; } while(temp_array.length 1){    trace(temp_array.splice(i...

经验教程

80

收藏

50
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部