原理:通過瀏覽器傳送變數,如
http://127.0.0.1/shengcheng.asp?id=90
代碼:
if SaveFile("/new/"&id&".html","http://127.0.0.1/news.asp?id="&id&"") then 中
/new"&id&".html",是你產生的檔案和路徑。http://127.0.0.1/news.asp?id="&id&""是asp的路徑
大家可以自己設定修改,其中 "&id&" 是讀取瀏覽器的變數。網址改成你自己的。
使用方法,給你的文章列表添加一個串連,如 http://127.0.0.1/shengcheng.asp?id=90
90這個變數相信大家會調用吧,這樣就能在/new目錄下產生按照id排列的html文章了
shengcheng.asp檔案如下:
<%
Dim id
id = Request("id")
%>
<%
if SaveFile("/new/"&id&".html","http://127.0.0.1/news.asp?id="&id&"") then
Response.write "已產生"
else
Response.write "沒有產生"
end if
function SaveFile(LocalFileName,RemoteFileUrl)
Dim Ads, Retrieval, GetRemoteData
On Error Resume Next
Set Retrieval = Server.CreateObject("Microso" & "ft.XM" & "LHTTP") '//把單詞拆開防止殺毒軟體誤殺
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject("Ado" & "db.Str" & "eam") '//把單詞拆開防止殺毒軟體誤殺
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile Server.MapPath(LocalFileName), 2
.Cancel()
.Close()
End With
Set Ads=nothing
if err <> 0 then
SaveFile = false
err.clear
else
SaveFile = true
end if
End function
%>
隨著網站訪問量的加大,每次從資料庫讀取都是以效率作為代價的,很多用ACCESS作資料庫的更會深有體會,靜態頁加在搜尋時,也會被優先考慮。互連網上流行的做法是將資料來源代碼寫入資料庫再從資料庫讀取產生靜態面,這樣無形間就加大了資料庫。將現有的ASP頁直接產生靜態頁,將會節省很多。