asp生成静态页面文件代码
asp教程生成静态页面文件代码
<!-- #include file="conn.asp" -->
<%
DB="database/database.mdb"
path=Server.MapPath(DB)
set conn=server.createobject("adodb.Connection")
connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source="&path
conn.Open connstr
Set rs=server.CreateObject("adodb.recordset")
%>
<%
sql="select * from news"
rs.open sql,conn,1,1
If rs.eof Then
Else
path5="./html/" '这个为生成后文件路径
Do While Not rs.eof
filename=Replace(Replace(Replace(rs("addtime"),":",""),"-","")," ","")&".html" '这个为生成后的文件名
url=".net教程friend/news.asp?id="&rs("id">http://localhost/netfriend/news.asp?id="&rs("id") '这个为动态页面地址,必须是http://****.asp格式的
Call createhtml(url,filename,path5)
rs.movenext
loop
End If
rs.close
Set rs=Nothing
Set conn=nothing
%>
<%
'功能:读取数据库教程内容,生成静态页面
'来自:www.zzzyk.com
'作者:wangsdong
'参数说明:
' url是动态页面的地址,必须是http://*****/**.asp格式
' filename为生成后的文件名
' path为存储生成后文件的文件夹名
'备注:支持原创程序,请保留此信息,谢谢
Function createhtml(url,filename,path)
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
path1=server.mappath(path)&""&filename
Set MyTextFile=MyFileObject.CreateTextFile(path1)
strurl=url
strTmp = GetHTTPPage(trim(strurl))
MyTextFile.WriteLine(strTmp)
MytextFile.Close
response.write "生成"&filename&"成功<br>"
Set MyFileObject=nothing
End function
Function getHTTPPage(url)
On Error Resume Next
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
If Err.number<>0 then
Response.Write "<p align='center'><font color='red'><b>服务器获取文件内容出错</b></font></p>"
Err.Clear
End If
End Function
Function BytesToBstr(body,Cset)
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 = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
%>
news.asp文件
<!-- #include file="www.zzzyk.com" -->
<%
id=request("id")
sql="select * from news where id="&id
rs.open sql,conn,1,1
If rs.eof Then
Else
title=rs("title")
content=rs("content")
End If
rs.close
%>
<style>
body td {font-size:12px;}
</style>
<TITLE> <%=title%> </TITLE>
<TABLE border="0" cellpadding="0" cellspacing="0" width="500">
<TR>
<TD style="border-bottom:1px #cccccc solid; height:40px; font-weight:bold; text-align:center;"><%=title%></TD>
</TR>
<TR>
<TD align="center"><div style="margin-top:20px; width:95%"><%=content%></div></TD>
</TR>
</TABLE>
补充:asp教程,高级应用