asp动态生成静态页面出现错误

2025-05-14 20:30:17
推荐回答(1个)
回答(1):

嗯,这是自然的,其占用空间相当小,不用担心
我被你搞懵了
所谓的生成静态页面,就是通过FSO把生成的静态文件写到服务器上
如果用FSO,XMLHTTP的话
首先XMLHTTP提交到模板页,你把返回的信息全部接收(其实就是在IE中查看源文件的内容了),然后通过FSO把接收到的内容写成一个文件,保存在服务器上就ok了
下面是原件:
<%
Dim FileName,UrlPath
FileName="/1.html" '要生成的文件路径及地址
UrlPath ="http://www.baidu.com" '这是你要进行转静态的页面
Call SaveToFile(FileName,GetTheHTMLCode(UrlPath))
Response.write UrlPath&" ==> "&FileName&"
。。快去看看"
'用XMLHTTP得到源码
Function GetTheHTMLCode(Url)
Dim Http
Set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",Url ,false
Http.send()
If Http.readystate<>4 then
Exit Function
End if
GetTheHTMLCode = BytesToBSTR(Http.responseBody,"GB2312")
Set Http=nothing
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
'保存文件
Sub SaveToFile(FilePath,FileContent)
Dim Fso ,File
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Set File = Fso.createTextFile(Server.Mappath(FilePath))
File.Write (FileContent)
File.Close
Set File=Nothing
Set Fso=Nothing
End Sub
%>