深入研究Application和Session对象
上一篇 / 下一篇 2007-04-13 16:55:16 / 个人分类:ASP
kPh [ B}6l[[0 用ASP编写虚拟社区、网上购物等程序时,Application和Session对象具有举足轻重的作用,能够灵活合理地运用这两个对象是提高程序质量的关键。下面让笔者根据自己在这方面的经验,向大家深入介绍一下ASP的这两个内建对象。51Testing软件测试网Q`v$i${c%m)M"_ ^ /tE8|}@+Jq;}b0 一、Application对象的成员概述51Testing软件测试网&fx*G {C R 51Testing软件测试网F1L_x+Q Application对象成员包括Application对象的集合、方法和事件。 @Je@X0 |,t]%R0n TZ0 ⒈Application对象的集合 PFJuk/V9Y051Testing软件测试网L:ov*wIL Contents集合:没有使用<OBJECT>元素定义的存储于Applicaiton对象中的所有变量的集合 (o|f?4n+O051Testing软件测试网d juBr1}.G*r StaticObjects:使用<OBJECT>元素定义的存储于Application对象中的所有变量 的集合 f6[qJ#Jp7K S0 iz(\\7X0 例:在default.asp中有如下赋值51Testing软件测试网%whZ:M0Y2n,ld)M 51Testing软件测试网*fo`1l9Aw application("a")="a" ^[C4s5b0 K B"\|~(H;}%i:R8WC0 application("b")=128 )q5Xcy?4p&uF/]U0 {"op? Di*K[,S0 application("c")=false *_*b){#r:Y`051Testing软件测试网g~#o_8L:k9?(G 则有contents集合51Testing软件测试网`:y|s3MX jq-~ 51Testing软件测试网 f$T6gF Zh9h(s application.contents(1)="a" '也可写为application.contents("a")="a" WocKc8NF'O OR0 $T SLG"KO/hN0 application.contents(2)=128 '也可写为application.contents("b")=12851Testing软件测试网7M/g+E7@K.J*A Ou]p)xw0 application.contents(3)=false '也可写为application.contents("c")=false )@)`]#g-q^A051Testing软件测试网j(r H.^!mBp 在此笔者推荐你在调用时使用类如application.contents("a")的方法,因为这样更为直观,如果用序号来表示的话则要考虑赋值的先后顺序。51Testing软件测试网)j~Zz YJ:h&z g Lk L0WB!l,R%q.t0 ⒉Application对象的方法 %Z h?gqK:gyJ:O A KK051Testing软件测试网5Dx/I0Nc8lq }%M Contents.Remove("变量名"):从Application.Contents集合中删除指定的变量 8h&SAa.l051Testing软件测试网tWr;g_]!X%sK Contents.RemoveAll() :把Application.Contents集合中的所有变量删除51Testing软件测试网[Bj)?~h 4e {-k'j6A\,G2l0 Lock() :锁定Application对象,使得只有当前的ASP页对内容能进行访问 +]#G8f1_u(z051Testing软件测试网Q{$},Dw^x Unlock() :解除对Application对象的锁定51Testing软件测试网7xk pGn5B@)r q&}%i)| -QhfN]t,h,I7| ]U0 例:在default.asp中: ^y6X-i$F0? Jk051Testing软件测试网!\i&@"z7S{ application("a")="a" 3j(^ ? G3VlWV0 aS$dy$j1L ~0 application("b")=12851Testing软件测试网B,Y#RX x/Ha%z 9q WF9Iy2C0 application("c")=false51Testing软件测试网,]l4Y/g!y0K#~8oRZ |g 51Testing软件测试网4q2X'tA"]'Iro^b response.write application.contents(1)&"<br>"51Testing软件测试网3uj1x1a9E(PJ:n^o;W |