ASP页面静态化批量生成代码分享(多种方法)(3)


content = Replace(Template,"{filed_name_1}",rs("filed_name_1")) '用字段值替换模板内容
content = Replace(content,"{filed_name_2}",rs("filed_name_2"))
......
content = Replace(content,"{filed_name_n}",rs("filed_name_n"))
genHtml content,Server.MapPath("htmfiles/"&rs("id")&".html") '将替换之后的Template字符串生成HTML文档,htmfiles为存储静态文件的目录,请手动建立
cnt = cnt + 1 '计数器加1
start = start + 1 '指针变量递增
rs.movenext
wend
If Not rs.eof Then '通过刷新的方式进行下一轮请求,并将指针变量start传递到下一轮
response.write "<meta http-equiv='refresh' content='0;URL=?start="&start&"'>"
Else
response.write "生成HTML文件完毕!"
End if
rs.Close()
Set rs = Nothing
objConn.Close()
Set objConn = Nothing
Function getTemplate(template)'读取模板的函数,返回字符串,template为文件名
Dim fso,f
set fso=CreateObject("Scripting.FileSystemObject")
set f = fso.OpenTextFile(template)
getTemplate=f.ReadAll
f.close
set f=nothing
set fso=Nothing
End Function
Sub genHtml(content,filename)'将替换后的内容写入HTML文档,content为替换后的字符串,filename为生成的文件名
Dim fso,f
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateTextFile(filename,true)'如果文件名重复将覆盖旧文件
f.Write content
f.Close
Set f = Nothing
set fso=Nothing
End Sub
%>