ASP使用模板生成静态页面

发现自己的记性越来越不好了。哎,怕忘了,把它记下来吧。
发现自己倒退了许多,为了糊口又做起了自己不会的ASP。哎!!!
其实跟ASP.NET的原理是一样的,可能通用。
简单的写一下。
其实这个东西也很简单,我在这里简单的写一下重要的东西。
变量替换就不写。
这个是读模板的操作,strModelFile是模板的名字
function readModel(strModelFile)
  readModel = ""
  Set fso = Server.CreateObject("Scripting.FileSystemObject")
  if (fso.FileExists(Server.MapPath(strModelFile))) Then
   Set fin = fso.OpenTextFile(Server.MapPath(strModelFile),1)
   readModel = fin.readall
   fin.close
   set fin = nothing
  end if
  set fso = nothing
 end function
 这个是写要生成的静态页面,strHtmlFile这个是要生成页面的名字,strContent这个是生成页面的HTML,
 function writeHtml(strHtmlFile,strContent)
 Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
'判断要放页面的文件夹是否存在,如果不存在就创建
 if (FileObject.FolderExists("d:\mydrivers\web\products\html\")) then
  else
   FileObject.CreateFolder("d:\mydrivers\web\products\html\")
 end if
'写文件,如果有就重写
 Set openFile=FileObject.CreateTextFile(strHtmlFile,true) 'true重新写
 openFile.writeline(strContent)
 openFile.close
 set FileObject=nothing
 set openFile=nothing
end function
posted @ 2006-04-10 13:43  lonelywolf  阅读(644)  评论(0编辑  收藏  举报