asp dictionary對象的用法
更新時(shí)間:2008年11月27日 00:51:41 作者:
關(guān)于script的dictionary對象,其實(shí)我想一開始ms是借鑒了python之類的動態(tài)腳本語言的,而且是面對客戶端開發(fā)的關(guān)于這一點(diǎn)可以參考wrox的asp程序員參考手冊里第137頁里
如果在session級保存一個(gè)dictionary對象會降低系統(tǒng)的性能,而在application級保存一個(gè)dictionary對象會導(dǎo)致web服務(wù)器崩潰,關(guān)于這個(gè)就不在多說了。
現(xiàn)在我們要考慮的是dictionary對象在單頁的時(shí)候,有哪些設(shè)計(jì)時(shí)的缺陷:
大家可以這么試試
set rs=server.createobject("adodb.recordset")
sql="select * from table"
rs.open sql,conn,1,3
set ttt=server.createobject("scripting.dictionary")
ttt.add "xxx",rs("field")
set rs=nothing
liu=ttt("xxx") '當(dāng)你這么做的時(shí)候會發(fā)現(xiàn)一件什么事呢?asp頁會告訴你發(fā)生意外?。。∵@個(gè)就很令人詫異了,什么是意外呢?很難說,后來經(jīng)過我反復(fù)的測試發(fā)現(xiàn)是因?yàn)椴荒馨裷s("field")的值直接給dictionary對象,經(jīng)過反復(fù)研究得出的結(jié)論是如下的:dictionry是把rs("field")的內(nèi)存地址給儲存了,這樣的話,我剛才寫的那個(gè)無疑是一種災(zāi)難,解決方法是把這個(gè)rs("field")放到一個(gè)變量里就可以解決了,但是dictionary對象難道不可以保存一個(gè)被nothing過的對象么?這個(gè)就是一個(gè)很大的疑問了,所以我又寫了這么一段程序,大家可以保存成try.htm看看效果的
<script language='vbscript'>
set ttt=createobject("scripting.dictionary")
ttt.add "liu","uuu"
set ddd=createobject("scripting.dictionary")
ddd.add "ppp",ttt
set ttt=nothing
bbb=ddd("ppp")("liu")
alert(bbb)
</script>
結(jié)果是什么?你會發(fā)現(xiàn)一段alert了uuu說明是沒有問題的,這就說明dictionary對象其實(shí)是把另一個(gè)
dictionary對象整個(gè)clone進(jìn)來了,這就更驗(yàn)證了wrox的書中寫的,dictionary對象在ms開發(fā)的時(shí)候其
實(shí)是針對客戶端的,這種說法了
還有對數(shù)組與dictionary合用的代碼也可以給大家看看的
<script language='vbscript'>
i=1
picname=("xxx")
str="set " & "pic_" & i & "=createobject(" & """" & "scripting.dictionary" & """" & ")"
execute(str)
str="pic_" & i & ".add " & """" & "picname" & """" & "," & """" & picname & """"
execute(str)
dim ttt()
redim ttt(5)
ttt(0)="uuu"
pic_1.add "item",ttt
liu=pic_1("picname")
set pic_2=createobject("scripting.dictionary")
erase ttt
redim ttt(5)
ttt(0)="iii"
nnn=pic_1("item")(0)
pic_2.add "rrr",ttt
zzz=pic_2("rrr")(0)
alert(liu)
alert(nnn)
alert(zzz)
</script>
現(xiàn)在我們要考慮的是dictionary對象在單頁的時(shí)候,有哪些設(shè)計(jì)時(shí)的缺陷:
大家可以這么試試
set rs=server.createobject("adodb.recordset")
sql="select * from table"
rs.open sql,conn,1,3
set ttt=server.createobject("scripting.dictionary")
ttt.add "xxx",rs("field")
set rs=nothing
liu=ttt("xxx") '當(dāng)你這么做的時(shí)候會發(fā)現(xiàn)一件什么事呢?asp頁會告訴你發(fā)生意外?。。∵@個(gè)就很令人詫異了,什么是意外呢?很難說,后來經(jīng)過我反復(fù)的測試發(fā)現(xiàn)是因?yàn)椴荒馨裷s("field")的值直接給dictionary對象,經(jīng)過反復(fù)研究得出的結(jié)論是如下的:dictionry是把rs("field")的內(nèi)存地址給儲存了,這樣的話,我剛才寫的那個(gè)無疑是一種災(zāi)難,解決方法是把這個(gè)rs("field")放到一個(gè)變量里就可以解決了,但是dictionary對象難道不可以保存一個(gè)被nothing過的對象么?這個(gè)就是一個(gè)很大的疑問了,所以我又寫了這么一段程序,大家可以保存成try.htm看看效果的
<script language='vbscript'>
set ttt=createobject("scripting.dictionary")
ttt.add "liu","uuu"
set ddd=createobject("scripting.dictionary")
ddd.add "ppp",ttt
set ttt=nothing
bbb=ddd("ppp")("liu")
alert(bbb)
</script>
結(jié)果是什么?你會發(fā)現(xiàn)一段alert了uuu說明是沒有問題的,這就說明dictionary對象其實(shí)是把另一個(gè)
dictionary對象整個(gè)clone進(jìn)來了,這就更驗(yàn)證了wrox的書中寫的,dictionary對象在ms開發(fā)的時(shí)候其
實(shí)是針對客戶端的,這種說法了
還有對數(shù)組與dictionary合用的代碼也可以給大家看看的
<script language='vbscript'>
i=1
picname=("xxx")
str="set " & "pic_" & i & "=createobject(" & """" & "scripting.dictionary" & """" & ")"
execute(str)
str="pic_" & i & ".add " & """" & "picname" & """" & "," & """" & picname & """"
execute(str)
dim ttt()
redim ttt(5)
ttt(0)="uuu"
pic_1.add "item",ttt
liu=pic_1("picname")
set pic_2=createobject("scripting.dictionary")
erase ttt
redim ttt(5)
ttt(0)="iii"
nnn=pic_1("item")(0)
pic_2.add "rrr",ttt
zzz=pic_2("rrr")(0)
alert(liu)
alert(nnn)
alert(zzz)
</script>
相關(guān)文章
用asp實(shí)現(xiàn)網(wǎng)頁調(diào)用doc附Response.ContentType 詳細(xì)列表
最近研究一下如何用網(wǎng)頁調(diào)用doc,最好能直接打開就成功了.2008-05-05ASP網(wǎng)頁模板的應(yīng)用: 讓程序和界面分離,讓ASP腳本更清晰,更換界面更容易
ASP網(wǎng)頁模板的應(yīng)用: 讓程序和界面分離,讓ASP腳本更清晰,更換界面更容易...2007-01-01ASP的Server.MapPath()不同參數(shù)返回路徑總結(jié)
這篇文章主要介紹了ASP的Server.MapPath()不同參數(shù)返回路徑總結(jié),也就是在Server.MapPath()中填入絕對路徑、相對路徑等情況的返回值總結(jié),需要的朋友可以參考下2014-07-07ASP 時(shí)間函數(shù)及如何獲取服務(wù)器時(shí)間的寫法
本文羅列了一些常用的ASP時(shí)間函數(shù)以及如何獲取服務(wù)器時(shí)間的寫法,感興趣的朋友可以了解下,就當(dāng)鞏固知識了希望本文對你有所幫助2013-01-01