ASP非模板生成静态页
首先我們要?jiǎng)?chuàng)建一個(gè)數(shù)據(jù)庫表news包括字段
id?? title???? contect???? date?
接著我們設(shè)置一個(gè)ASP數(shù)據(jù)顯示頁shownew.asp
代碼如下:
<%@codepage=936%>
<%
dim connstr,dirs
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("text.mdb")&";Jet OLEDB:Database "
set conn=server.createobject("ADODB.CONNECTION")
if conn.state=1 then
conn.Close
end if
conn.Open connstr
new_id=Request.QueryString("new_id")
if not new_id="" then
set rs=Server.CreateObject("Adodb.RecordSet")
rs.Open "select * from news where id="&new_id,conn,1,1
do while not rs.eof
Response.Write("<table><caption>"&rs(1)&"</caption>")
Response.Write("<tr><td>"&rs(2)&"</td></tr><tr><td> 發(fā)布時(shí)間 :"&rs(3)&"</td></tr></table>")
rs.MoveNext
loop
rs.Close
set rs=Nothing
end if
conn.Close
set conn=Nothing
%>?
最后就是關(guān)鍵的靜態(tài)頁生成頁了dytost.asp
代碼如下:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<base target="_blank" />
<iframe id="myiframe"? style=" display:none"></iframe>
<%
dim connstr,dirs
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("text.mdb")&";Jet OLEDB:Database Password=qgyqgyqgy"
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.Clear
else
conn.Open connstr
end if
if request("page")<>"" then
page=cint(request("page"))
else???????
page=1
end if
set rs=Server.CreateObject("Adodb.RecordSet")
rs.Open "select * from new ",conn,1,1
mpage1=rs.Recordcount
rs.move? (page-1)*1
url="http://localhost/example/asp生成靜態(tài)頁/shownew.asp?new_id="&rs(0)//這里一定要是完整URL
fvfile="new"&rs(0)&".html"
response.write"<b><font color=""#FF0000"">"&page&"</font>/<font color=""#FF0000"">"&mpage1&"</font> 正在生成新聞頁面,請等待......</b><span id=showImport></span><IE:Download ID=""oDownload"" STYLE=""behavior:url(#default#download)"" />"
Response.Write"<script>document.getElementById('myiframe').src='"&url&"'</script>"
savefile? url,fvfile
rs.Close
set rs=Nothing
if page<mpage1 then
Response.Write"<meta http-equiv=""refresh"" content=""0;url=dytost.asp?page="&page+1&"'"">"
end if
function savefile(url,fvfile)
on error resume next?
url=url//這一定要用完整URL地址
wstr = GetPage(url)+url
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set CrFi=fs.CreateTextFile(server.MapPath(fvfile))
Crfi.Writeline(wstr)
set CrFi=nothing
set fs=nothing
//Response.Write("<script> alert('"&fvfile&"生成成功')</script>")
?end function
Function GetPage(url)
??? dim Retri
??? Set Retri = CreateObject("Microsoft.XMLHTTP")
?? With Retri
??? .Open "Get", url, False
??? .Send
??? GetPage = BytesToBstr(.ResponseBody)
??? End With
??? Set Retri = Nothing
??? End Function
??
??? Function BytesToBstr(body)
??? dim objstream
??? set objstream = Server.CreateObject("adodb.stream")
??? objstream.Type = 1
??? objstream.Mode =3
??? objstream.Open
??? objstream.Write body
??? objstream.Position = 0
??? objstream.Type = 2
??? objstream.Charset = "GB2312"
??? BytesToBstr = objstream.ReadText
??? objstream.Close
??? set objstream = nothing
End Function
%>
好了現(xiàn)在就可了,
不過有一點(diǎn)大家一定要注意啊!因?yàn)檫@個(gè)是先將代碼靜態(tài)化然后,再將靜態(tài)化的代碼生成靜態(tài)頁的,所以由于生成的速度太快,可能第一次生成的文件是顯示不正常的,這是我們只要在運(yùn)行一下這個(gè)dytost.asp文件就可以了,大家也可以在程序中添加時(shí)間間隔攝者的代碼來避免這個(gè)情況的出現(xiàn)
轉(zhuǎn)載于:https://blog.51cto.com/shenymce/390953
總結(jié)
以上是生活随笔為你收集整理的ASP非模板生成静态页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一点一滴linux
- 下一篇: 推荐一个wpfsliverlight的图