当前位置:编程学习 > asp >>

通过模板生成静态页面示例

答案:'/////////////////////////////////////////////////////
'通过模板生成静态页面示例
'作者:griefforyou
'/////////////////////////////////////////////////////

<!--模块文件(template.htm)-->
<html>
<head>
<title>%TITLE%</title>
</head>
<body>
%CONTENT%
</body>
</html>

<!--TestTemplate.asp-->
<%
Dim fso,f
Dim strTitle,strContent,strOut
'创建文件系统对象
Set fso=Server.CreateObject("Scripting.FileSystemObject")

'打开网页模板文件,读取模板内容
Set f=fso.OpenTextFile(Server.MapPath("Template.htm"))
strOut=f.ReadAll
f.close

strTitle="这是生成的网页标题"
strContent="这是生成的网页内容"

'用真实内容替换模板中的标记
strOut=Replace(strOut,"%TITLE%",strTitle)
strOut=Replace(strOut,"%CONTENT%",strContent)

'创建要生成的静态页
Set f=fso.CreateTextFile(Server.MapPath("New.htm"),true)

'写入网页内容
f.WriteLine strOut
f.close

Response.Write "生成静态页成功!"

'释放文件系统对象
set f=Nothing
set fso=Nothing
%>


上一个:无刷新聊天室的技术实现
下一个:【编程】开源(OpenSource) - 反向链接(Referrers)系统

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,