最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp生成静态页面文件代码
时间:2022-07-02 23:03:42 编辑:袖梨 来源:一聚教程网
<%
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="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.111com.net
'作者: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&"成功
"
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 "
服务器获取文件内容出错
"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文件
<%
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
%>
<%=title%> |
<%=content%> |