絕妙的asp生成靜態(tài)頁(yè)面_第1頁(yè)
絕妙的asp生成靜態(tài)頁(yè)面_第2頁(yè)
絕妙的asp生成靜態(tài)頁(yè)面_第3頁(yè)
絕妙的asp生成靜態(tài)頁(yè)面_第4頁(yè)
絕妙的asp生成靜態(tài)頁(yè)面_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、ASP中生成靜態(tài)頁(yè)面技術(shù)作 者:漢南居士關(guān)鍵字:ASP技術(shù)應(yīng)用 % dim str function menu(id) set rs=server.CreateObject(adodb.recordset) sql=select * from menu where id1=&id& order by url,id rs.open sql,conn,1,1 str=str+chr(13) i=1 while not rs.eof ChildCount=conn.execute(select count(*) from menu where id1=&rs(id)(0) if ChildCount

2、=0 then if i=rs.recordcount then menutype=file1 else menutype=file end if menuname=&rs(menuname)& onmouseup= else if i=rs.recordcount then menutype=menu3 listtype=list1 onmouseup= onMouseUp=change1(a&rs(id)&,b&rs(id)&); else menutype=menu1 listtype=list onmouseup= onMouseUp=change2(a&rs(id)&,b&rs(id

3、)&); end if menuname=rs(menuname) end if str=str+&menuname&+chr(13) if ChildCount0 then str=str+chr(13) menu(rs(id) str=str+chr(13) end if rs.movenext i=i+1 wend str=str+chr(13) rs.close set rs=nothing end function menu(0) set fso=server.CreateObject(scripting.filesystemobject) set f1=fso.opentextfi

4、le(server.MapPath(demo.htm),2,true) f1.write(;) f1.write() f1.write() f1.write() f1.write(哈哈!這回速度超快了吧?) f1.write() f1.write() f1.write() f1.write() f1.write() f1.write() f1.write(提供最新下載管理) f1.write(str) f1.write() f1.write() f1.close set fso=nothing response.Redirect(demo.htm) %絕妙的a

5、sp生成靜態(tài)頁(yè)面 作 者:漢南居士關(guān)鍵字:ASP技術(shù)應(yīng)用隨著網(wǎng)站訪問(wèn)量的加大,每次從數(shù)據(jù)庫(kù)讀取都是以效率作為代價(jià)的,很多用ACCESS作數(shù)據(jù)庫(kù)的更會(huì)深有體會(huì),靜態(tài)頁(yè)加在搜索時(shí),也會(huì)被優(yōu)先考慮。互聯(lián)網(wǎng)上流行的做法是將數(shù)據(jù)源代碼寫(xiě)入數(shù)據(jù)庫(kù)再?gòu)臄?shù)據(jù)庫(kù)讀取生成靜態(tài)面,這樣無(wú)形間就加大了數(shù)據(jù)庫(kù)。將現(xiàn)有的ASP頁(yè)直接生成靜態(tài)頁(yè),將會(huì)節(jié)省很多。下面的例子是將、index.asp?id=1/index.asp?id=2/index.asp?id=3/這三個(gè)動(dòng)態(tài)頁(yè)面,分別生成ndex1.htm,index2.htm,index3.htm存在根目錄下面%dim strUrl,Item_Classid,id,Fil

6、eName,FilePath,Do_Url,Html_TempHtml_Temp=For i=1 To 3Html_Temp = Html_Temp&Item_Classid = iFileName = Index&Item_Classid&.htmFilePath = Server.MapPath(/)&FileNameHtml_Temp = Html_Temp&FilePath&Do_Url = http:/Do_Url = Do_Url&Request.ServerVariables(SERVER_NAME)&/main/index.aspDo_Url = Do_Url&?Item_Cl

7、assid=&Item_ClassidstrUrl = Do_Urldim objXmlHttpset objXmlHttp = Server.CreateObject(Microsoft.XMLHTTP)objXmlHttp.open GET,strUrl,falseobjXmlHttp.send()Dim binFileDatabinFileData = objXmlHttp.responseBodyDim objAdoStreamset objAdoStream = Server.CreateObject(ADODB.Stream)objAdoStream.Type = 1objAdoS

8、tream.Open()objAdoStream.Write(binFileData)objAdoStream.SaveToFile FilePath,2 objAdoStream.Close()NextHtml_Temp = Html_Temp&%Response.Write ( 成功生成文件: )Response.Write ( )Response.Write Html_Temp%-另一種方法-ASP生成靜態(tài)頁(yè)經(jīng)過(guò)我在網(wǎng)上的搜索,似乎要避免fso生成靜態(tài)頁(yè)的可能性不大,但是,我順便搜索了些生成靜態(tài)頁(yè)的教程希望大家用的著ASP生成靜態(tài)網(wǎng)頁(yè)的方法隨著網(wǎng)站訪問(wèn)量的加大,每次從數(shù)據(jù)庫(kù)讀取都是以效率

9、作為代價(jià)的,很多用ACCESS作數(shù)據(jù)庫(kù)的更會(huì)深有體會(huì),靜態(tài)頁(yè)加在搜索時(shí),也會(huì)被優(yōu)先考慮?;ヂ?lián)網(wǎng)上流行的做法是將數(shù)據(jù)源代碼寫(xiě)入數(shù)據(jù)庫(kù)再?gòu)臄?shù)據(jù)庫(kù)讀取生成靜態(tài)面,這樣無(wú)形間就加大了數(shù)據(jù)庫(kù)。將現(xiàn)有的ASP頁(yè)直接生成靜態(tài)頁(yè),將會(huì)節(jié)省很多。下面的例子是將、index.asp?id=1/index.asp?id=2/index.asp?id=3/這三個(gè)動(dòng)態(tài)頁(yè)面,分別生成ndex1.htm,index2.htm,index3.htm存在根目錄下面:%dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_TempHtml_Temp=For i=1 To

10、 3Html_Temp = Html_Temp&Item_Classid = iFileName = Index&Item_Classid&.htmFilePath = Server.MapPath(/)&FileNameHtml_Temp = Html_Temp&FilePath&Do_Url = http:/Do_Url = Do_Url&Request.ServerVariables(SERVER_NAME)&/main/index.aspDo_Url = Do_Url&?Item_Classid=&Item_ClassidstrUrl = Do_Urldim objXmlHttpset

11、 objXmlHttp = Server.CreateObject(Microsoft.XMLHTTP)objXmlHttp.open GET,strUrl,falseobjXmlHttp.send()Dim binFileDatabinFileData = objXmlHttp.responseBodyDim objAdoStreamset objAdoStream = Server.CreateObject(ADODB.Stream)objAdoStream.Type = 1objAdoStream.Open()objAdoStream.Write(binFileData)objAdoSt

12、ream.SaveToFile FilePath,2 objAdoStream.Close()NextHtml_Temp = Html_Temp&%Response.Write ( 成功生成文件: )Response.Write ( )Response.Write Html_Temp%非摸板生成靜態(tài)頁(yè)目前已經(jīng)有很多生成html的新聞系統(tǒng),但是都是用的模板,本函數(shù)實(shí)現(xiàn)把a(bǔ)sp頁(yè)面產(chǎn)生的html代碼保存成為一個(gè)html文件,這樣就沒(méi)有必要改動(dòng)原來(lái)的頁(yè)面就可以輕松完成一個(gè)生成html的新聞系統(tǒng)了。_由于代碼比較短,這里就不進(jìn)行注釋了%當(dāng)目標(biāo)頁(yè)面的包含文件即i nclude的頁(yè)面里邊存在respons

13、e.End()的時(shí)候本程序有問(wèn)題注意:本文件一定要放在filename指向的文件的同一目錄下dim hughchiu_rtcodeFunction get_exe_code(filename)dim execodedim tmp_strDim re,re1,content,fso,f,aspStart,aspEnddim ms,mexecode = set fso=CreateObject(Scripting.FileSystemObject)set f=fso.OpenTextFile(server.mappath(filename)content=f.ReadAllf.closeset f

14、=nothingset fso=nothingset re = new regexpre.ignorecase = truere.global = truere.pattern = content = re.replace(content,)re.global = falsere.pattern = doset ms = re.execute(content)if ms.count0 thenset m = ms(0)tmp_str = get_exe_code(m.submatches(0)content = re.replace(content, tmp_str)elseexit doen

15、d ifloopset m = nothingset ms = nothingre.pattern=s*=aspEnd=1aspStart=inStr(aspEnd,content,aspEnd+1 execode = execode&vbcrlf& hughchiu_rtcode = hughchiu_rtcode&replace( replace(Mid(content,aspEnd,aspStart-aspEnd-2),), vbcrlf, &vbcrlf&)&vbcrlf aspEnd=inStr(aspStart,content,%)+2 tmp_str = Mid(content,

16、aspStart,aspEnd-aspStart-2) doset ms = re1.execute(tmp_str)if ms.count0 thenset m = ms(0)tmp_str = re1.replace(tmp_str, hughchiu_rtcode = hughchiu_rtcode&m.submatches(0)elseexit doend ifloop set m = nothing set ms = nothing execode = execode& re.replace(tmp_str,hughchiu_rtcode = hughchiu_rtcode&) as

17、pStart=inStr(aspEnd,content,%)+2loopset re1 = nothingset re=nothingexecode = execode&vbcrlf& hughchiu_rtcode = hughchiu_rtcode&replace( replace(Mid(content,aspEnd), , ), vbcrlf, &vbcrlf& )&vbcrlfget_exe_code = End Functionfunction asp2html(filename)dim codecode = replace( replace( replace( get_exe_c

18、ode(filename), hughchiu_rtcode = hughchiu_rtcode&vbcrlf, ), , )response.Write(code)execute(code)response.Write( hughchiu_rtcode )asp2html = hughchiu_rtcodeend function%使用范例:set fso=CreateObject(Scripting.FileSystemObject)set f=fso.CreateTextFile( server.mappath( youpage.htm ), true )f.WriteLine( asp

19、2html(youpage.asp) )f.closeset f = nothingset fso = nothing 來(lái)源:互聯(lián)網(wǎng)閱讀:494 次日期:2006-6-19一個(gè)用asp生成html的新方法 作 者:漢南居士關(guān)鍵字:ASP技術(shù)應(yīng)用目前已經(jīng)有很多生成html的新聞系統(tǒng),但是都是用的模板,本函數(shù)實(shí)現(xiàn)把a(bǔ)sp頁(yè)面產(chǎn)生的html代碼保存成為一個(gè)html文件,這樣就沒(méi)有必要改動(dòng)原來(lái)的頁(yè)面就可以輕松完成一個(gè)生成html的新聞系統(tǒng)了。_ 由于代碼比較短,這里就不進(jìn)行注釋了%當(dāng)目標(biāo)頁(yè)面的包含文件即#include的頁(yè)面里邊存在response.end()的時(shí)候本程序有問(wèn)題注意:本文件一定要放在f

20、ilename指向的文件的同一目錄下dim hughchiu_rtcodefunction get_exe_code(filename) dim execode dim tmp_str dim re,re1,content,fso,f,aspstart,aspend dim ms,m execode = set fso=createobject(scripting.filesystemobject) set f=fso.opentextfile(server.mappath(filename) content=f.readall f.close set f=nothing set fso=no

21、thing set re = new regexp re.ignorecase = true re.global = true re.pattern = content = re.replace(content,) re.global = false re.pattern = do set ms = re.execute(content)if ms.count0 thenset m = ms(0)tmp_str = get_exe_code(m.submatches(0)content = re.replace(content, tmp_str)elseexit doend if loop s

22、et m = nothing set ms = nothing re.pattern=s*= aspend=1 aspstart=instr(aspend,content,aspend+1 execode = execode!amp;vbcrlf!amp; hughchiu_rtcode = hughchiu_rtcode!amp;!amp;replace( replace(mid(content,aspend,aspstart-aspend-2),), vbcrlf, !amp;vbcrlf!amp;)!amp;!amp;vbcrlf aspend=instr(aspstart,conten

23、t,%)+2 tmp_str = mid(content,aspstart,aspend-aspstart-2) doset ms = re1.execute(tmp_str)if ms.count0 thenset m = ms(0)tmp_str = re1.replace(tmp_str, hughchiu_rtcode = hughchiu_rtcode!amp;!amp;m.submatches(0)elseexit doend ifloop set m = nothing set ms = nothing execode = execode!amp; re.replace(tmp_str,hughchiu_rtcode = hughchiu_rtcode!amp;) aspst

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論