Web page generation of static HTML file has many advantages, such as the creation of HTML Web pages are included in the search engine, not only included in the quick also included in the whole. The front desk is out of data access, reduces pressure on database access, and speeds up Web page opening.
Like Www.aspid.cn Main station on the use of Tsys to generate HTML files!
So Yin Qing recently to generate HTML more interested, read a lot of articles, but also a little harvest.
1, the following example directly uses the FSO to write HTML code to a file and then generate an. HTML-formatted file <%
filename= "test.htm"
If Request ("Body") <> "" Then
Set fso = Server.CreateObject ("Scripting.FileSystemObject")
Set htmlwrite = FSO. CreateTextFile (Server.MapPath ("&filename&"))
Htmlwrite.write " Htmlwrite.write " Htmlwrite.close
Set Fout=nothing
Set fso=nothing
End If
%>
2, but it is inconvenient to generate HTML files in the above method, and the second method is to use template technology to replace the value of special code in the template with the values accepted from the form or database field, and to complete the template function; Generates an HTML file for all the template code that is eventually replaced. This technique is used more, and most of the CMS uses this type of method.
Template.htm '//template file<html>
<head>
<title>$title$ by aspid.cn</title>
</head>
<body>
$body$
</body>
</html> ?
TestTemplate.asp '// 生成Html <%
Dim fso,htmlwrite
Dim strTitle,strContent,strOut
'// 创建文件系统对象
Set fso=Server.CreateObject("Scripting.FileSystemObject")
'// 打开网页模板文件,读取模板内容
Set htmlwrite=fso.OpenTextFile(Server.MapPath("Template.htm"))
strOut=f.ReadAll
htmlwrite.close
strTitle="生成的网页标题"
strContent="生成的网页内容"
'// 用真实内容替换模板中的标记
strOut=Replace(strOut,"$title$",strTitle)
strOut=Replace(strOut,"$body$",strContent)
'// 创建要生成的静态页
Set htmlwrite=fso.CreateTextFile(Server.MapPath("test.htm"),true)
'// 写入网页内容
htmlwrite.WriteLine strOut
htmlwrite.close
Response.Write "生成静态页成功!"
'// 释放文件系统对象
set htmlwrite=Nothing
set fso=Nothing
%>