靜態|網頁|靜態 隨著網站訪問量的加大,每次從資料庫讀取都是以效率作為代價的,很多用ACCESS作資料庫的更會深有體會,靜態頁加在搜尋時,也會被優先考慮。互連網上流行的做法是將資料來源代碼寫入資料庫再從資料庫讀取產生靜態面,這樣無形間就加大了資料庫。將現有的ASP頁直接產生靜態頁,將會節省很多。
下面的例子是將、index.asp?id=1/index.asp?id=2/index.asp?id=3/這三個動態網頁面,分別產生ndex1.htm,index2.htm,index3.htm存在根目錄下面:
Code:
<%
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("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFileData
binFileData = objXmlHttp.responseBody
Dim objAdoStream
set objAdoStream = Server.CreateObject("ADODB.Stream")
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
%>