绝妙的asp生成静态页面_第1页
绝妙的asp生成静态页面_第2页
绝妙的asp生成静态页面_第3页
绝妙的asp生成静态页面_第4页
绝妙的asp生成静态页面_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、ASP中生成静态页面技术作 者:汉南居士关键字:ASP技术应用 % 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) %绝妙的asp生成静态页面 作 者:汉南居士

5、关键字:ASP技术应用随着网站访问量的加大,每次从数据库读取都是以效率作为代价的,很多用ACCESS作数据库的更会深有体会,静态页加在搜索时,也会被优先考虑。互联网上流行的做法是将数据源代码写入数据库再从数据库读取生成静态面,这样无形间就加大了数据库。将现有的ASP页直接生成静态页,将会节省很多。下面的例子是将、index.asp?id=1/index.asp?id=2/index.asp?id=3/这三个动态页面,分别生成ndex1.htm,index2.htm,index3.htm存在根目录下面%dim strUrl,Item_Classid,id,FileName,FilePath,Do

6、_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_Classid=&Item_Class

7、idstrUrl = 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 = 1objAdoStream.Open()objAd

8、oStream.Write(binFileData)objAdoStream.SaveToFile FilePath,2 objAdoStream.Close()NextHtml_Temp = Html_Temp&%Response.Write ( 成功生成文件: )Response.Write ( )Response.Write Html_Temp%-另一种方法-ASP生成静态页经过我在网上的搜索,似乎要避免fso生成静态页的可能性不大,但是,我顺便搜索了些生成静态页的教程希望大家用的着ASP生成静态网页的方法随着网站访问量的加大,每次从数据库读取都是以效率作为代价的,很多用ACCESS作数

9、据库的更会深有体会,静态页加在搜索时,也会被优先考虑。互联网上流行的做法是将数据源代码写入数据库再从数据库读取生成静态面,这样无形间就加大了数据库。将现有的ASP页直接生成静态页,将会节省很多。下面的例子是将、index.asp?id=1/index.asp?id=2/index.asp?id=3/这三个动态页面,分别生成ndex1.htm,index2.htm,index3.htm存在根目录下面:%dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_TempHtml_Temp=For i=1 To 3Html_Temp = Htm

10、l_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 objXmlHttp = Ser

11、ver.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)objAdoStream.SaveToFile F

12、ilePath,2 objAdoStream.Close()NextHtml_Temp = Html_Temp&%Response.Write ( 成功生成文件: )Response.Write ( )Response.Write Html_Temp%非摸板生成静态页目前已经有很多生成html的新闻系统,但是都是用的模板,本函数实现把asp页面产生的html代码保存成为一个html文件,这样就没有必要改动原来的页面就可以轻松完成一个生成html的新闻系统了。_由于代码比较短,这里就不进行注释了%当目标页面的包含文件即i nclude的页面里边存在response.End()的时候本程序有问题注

13、意:本文件一定要放在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=nothingset fso=n

14、othingset 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 doend ifloopset m = n

15、othingset 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,aspStart,aspEnd-a

16、spStart-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&) aspStart=inStr(aspE

17、nd,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_code(filename), hu

18、ghchiu_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( asp2html(youpage.asp

19、) )f.closeset f = nothingset fso = nothing 来源:互联网阅读:494 次日期:2006-6-19一个用asp生成html的新方法 作 者:汉南居士关键字:ASP技术应用目前已经有很多生成html的新闻系统,但是都是用的模板,本函数实现把asp页面产生的html代码保存成为一个html文件,这样就没有必要改动原来的页面就可以轻松完成一个生成html的新闻系统了。_ 由于代码比较短,这里就不进行注释了%当目标页面的包含文件即#include的页面里边存在response.end()的时候本程序有问题注意:本文件一定要放在filename指向的文件的同一目录

20、下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=nothing set re = ne

21、w 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 set m = nothing se

22、t 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,content,%)+2 tmp_str =

23、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;) aspstar

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论