« Css入门实例:内部样式表SQL Server和Oracle常用函数对比 »

ASP生成静态页面类

<%
'*******************************************************************************************
' 创 建 人:cuiwl (longchengfy@hotmail.com)
' 更新时间:2006-11-14 10:11
' 说 明:生成静态页面
'*******************************************************************************************
class savefile
public foldername, filename, fileurl
public fso, stream, xmlhttp
public thiserror
private i, j

' 初试化
private sub class_initialize()
foldername = ""
filename = "savefile.htm"
set fso = server.createobject("scripting.filesystemobject")
set stream = server.createobject("adodb.stream")
dim xmlhttparr(3)
xmldocarr(0) = "msxml2.serverxmlhttp.6.0"
xmldocarr(1) = "msxml2.serverxmlhttp.5.0"
xmldocarr(2) = "msxml2.serverxmlhttp.4.0"
xmldocarr(3) = "msxml2.serverxmlhttp.3.0"
for i = 0 to ubound(xmldocarr)
xmldocstr = xmldocarr(i)
if isobj(xmldocstr) then exit for
next
erase xmldocarr
if objerr(xmldocstr) then
response.clear
rwrite thiserror
response.end
end if
set xmlhttp = server.createobject (xmldocstr)
end sub

private sub class_terminate()
if isobject(fso) then set fso = nothing
if isobject(stream) then set stream = nothing
if isobject(xmlhttp) then set xmlhttp = nothing
end sub

private function sco(byval objstr)
set sco = server.createobject (objstr)
end function

private function isobj(byval objstr)
dim testobj
on error resume next
set testobj = server.createobject (objstr)
if -2147221005 <> err then
isobj = true
else
isobj = false
end if
set testobj = nothing
err.clear
end function

private function objerr(byval objstr)
objerr = false
if not isobj(objstr) then
thiserror = objstr & "组件注册错误!"
objerr = true
end if
end function

' Html文件生成
public sub save()
dim filepath
dim binFileData
filepath = server.mappath(foldername & "/" & filename)
if not fso.folderexists(server.mappath(foldername)) and foldername <> "" then
fso.createfolder server.mappath(foldername)
end if
xmlhttp.open "GET",fileurl,false
xmlhttp.send()
binFileData = xmlhttp.responseBody
Stream.Type = 1
Stream.Open()
Stream.Write(binFileData)
Stream.SaveToFile FilePath, 2
Stream.Close()
end sub
End class
'*******************************************************************************************
%>

调用:

public sub intro_save()
dim i
i = code_int(request.querystring("i"))
dim objsave : set objsave = new savefile
objsave.foldername = webdir & "web.intro"
objsave.fileurl = "http://"; & request.servervariables("SERVER_NAME") & webdir & "web.intro/index.asp?i=" & i
objsave.filename = i & ".htm"
objsave.save
if i = 0 then
objsave.filename = "index.htm"
objsave.save
end if
unobj objsave
thismessage = "已生成静态文件!<a href=""" & webdir & "web.intro/" & i & ".htm"" target=""_blank"">浏览</a>"
intro_list
End sub

原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。