ASP生成静态网页的方法

2007-12-04 21:09:59

技术资料 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_Url,Html_Temp

Html_Temp="<UL>"

For i=1 To 3

Html_Temp = Html_Temp&"<LI>"

Item_Classid = i

FileName = "Index"&Item_Classid&".htm"

FilePath = Server.MapPath("/")&""&FileName

Html_Temp = Html_Temp&FilePath&"</LI>"

Do_Url = "http://"

Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")&"/main/index.asp"

Do_Url = Do_Url&"?Item_Classid="&Item_Classid

strUrl = Do_Url

dim objXmlHttp

set objXmlHttp = Server.CreateObject("Micro"&"soft"&"."&"XML"&"HTTP")'防止卡巴误报

objXmlHttp.open "GET",strUrl,false

objXmlHttp.send()

Dim binFileData

binFileData = objXmlHttp.responseBody

Dim objAdoStream

set objAdoStream = Server.CreateObject("ADO"&"DB"&"."&"Str"&"eam")'防止卡巴误报

objAdoStream.Type = 1

objAdoStream.Open()

objAdoStream.Write(binFileData)

objAdoStream.SaveToFile FilePath,2

objAdoStream.Close()

Next

Html_Temp = Html_Temp&"<UL>"

%>

<%

Response.Write ( "成功生成文件:" )

Response.Write ( "<BR>" )

Response.Write Html_Temp

%>