以下是利用模版生成HTML的代码 
例: 
 
 
生成代码: *.asp 
 
<% 
fname="template.htm" 
dim replaceweb(2) 
replaceweb(0)="haha" 
replaceweb(1)="模版生成静态页面"       '设置生成内容,实际中可从数据库读取 
replaceweb(2)="模版生成静态页面实例" 
set fso=server.createobject("scripting.filesystemobject") 
set file=fso.opentextfile(server.mappath(fname),1,True) 
FSOFileRead = file.ReadAll 
set file=nothing 
for i=0 to 2  
FSOFileRead=Replace(FSOFileRead,"$HTMLWEB["&i&"]",replaceweb(i)) 
next 
Set outfile = fso.CreateTextFile(Server.Mappath("index.htm")) 
outfile.Write FSOFileRead 
outfile.close 
Set outfile=nothing 
Set fso=nothing 
%> 
 
模板:template.htm 
 
<html> 
<head> 
<title>$HTMLWEB[0]</title> 
</head> 
<body> 
<center> 
<h1>$HTMLWEB[1]</h1><hr> 
$HTMLWEB[2] 
</center> 
</body> 
</html> |