亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ASP中利用execute實(shí)現(xiàn)動(dòng)態(tài)包含文件的方法

 更新時(shí)間:2020年09月14日 13:30:24   投稿:mdxy-dxy  
本文介紹了ASP中動(dòng)態(tài)包含ASP文件,并使其中ASP類(lèi)(Class)可實(shí)例化的方法,需要的朋友可以參考下

在ASP中include文件形如 #include file=function.asp,這是最簡(jiǎn)單也是最常用的包含文件方法,青島星網(wǎng)下面跟大家分享:根據(jù)不同的需求,包含不同的文件的函數(shù)。

ASP動(dòng)態(tài)包含文件的實(shí)現(xiàn)函數(shù)

Function include(filename)
Dim re,content,fso,f,aspStart,aspEnd
set fso=CreateObject("Scripting.FileSystemObject")
set f=fso.OpenTextFile(server.mappath(filename))
content=f.ReadAll
f.close
set f=nothing
set fso=nothing
set re=new RegExp
re.pattern="^\s*="
aspEnd=1
aspStart=inStr(aspEnd,content,"<%")+2
do while aspStart>aspEnd+1
 Response.write Mid(content,aspEnd,aspStart-aspEnd-2)
 aspEnd=inStr(aspStart,content,"%\>")+2
 Execute(re.replace(Mid(content,aspStart,aspEnd-aspStart-2),"Response.Write "))
 aspStart=inStr(aspEnd,content,"<%")+2
loop
Response.write Mid(content,aspEnd)
set re=nothing
End Function

其實(shí)是寫(xiě)一個(gè)動(dòng)態(tài)包含的函數(shù),這樣每次調(diào)用時(shí)候代碼簡(jiǎn)潔,也方便,使用方法:

include("***.asp")'注意,這里的include是函數(shù)名哦,不要搞混哦。

下面是其他網(wǎng)友的補(bǔ)充大家參考一下

ASP中,include file/virtual 是優(yōu)先腳本代碼處理的,所以無(wú)法使用include動(dòng)態(tài)包含ASP文件。我們可以使用Execute函數(shù)動(dòng)態(tài)執(zhí)行所需代碼。

方法:

Execute(ASP代碼)

例子:(vbCrLf為換行符)

Execute("Class clsAbc"&vbCrLf&"Public Function output"&vbCrLf&"Response.Write 123"&vbCrLf&"End Function"&vbCrLf&"End Class") 

Dim objAbc 
Set objAbc = New clsAbc 
objAbc.output 
Set objAbc = Nothing 

使用時(shí)可以用從文件或數(shù)據(jù)庫(kù)讀取出ASP代碼再執(zhí)行,注意,所執(zhí)行的代碼中不應(yīng)包含<%和%>
注意不要與Server.Execute混淆,Server.Execute參數(shù)為ASP虛擬路徑,并且使用該函數(shù)不但不能動(dòng)態(tài)聲明Class類(lèi),甚至不可以給主程序段的變量賦值。

例子:

main.asp

Dim strAbc,objAbc 
strAbc = "Test" 
Server.Execute("sub.asp") 
Response.Write strAbc 
Set objAbc = New clsAbc 
objAbc.output 
Set objAbc = Nothing 

sub.asp

strAbc = "Execute" 
Class clsAbc 
 Public Function output 
 Response.Write "Class" 
 End Function 
End Class 

執(zhí)行main.asp后,將僅輸出Test,而objAbc則不能實(shí)例化。

相關(guān)文章

最新評(píng)論