ASP產生html靜態頁面的方法

來源:互聯網
上載者:User

 原理:通過瀏覽器傳送變數,如

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頁直接產生靜態頁,將會節省很多。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.