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" <body> output title content: " & Request.Form ("title") & "<br/> Output Body content:" & Request.Form ("Body") & "</body> Htmlwrite.close
Set fout=nothing
Set fso=nothing
End If
%>
<form name=" form "method=" post "Action=" ""
<input name= "title" value= "title" SIZE=26>
<br>
? <textarea name= "Body" > Body</textarea>
<br>
? <br>
? <input type= "Submit" name= "submit" value= "Generate HTML" >
</form>
2, but it's very inconvenient to generate HTML files in the above way, the second approach is to use template technology to replace the value of special code in the template with a value accepted from the form or database field, complete the template function, and generate an HTML file for all the template code that is eventually replaced. This technique is used more, Most CMS uses this type of method.
Template.htm '//template file
<title> $title $ by aspid.cn</title>
<body>
$body $
</body>
Testtemplate.asp '//Generate HTML
<%
Dim Fso,htmlwrite
Dim Strtitle,strcontent,strout
'//Create File system objects
Set fso=server.createobject ("Scripting.FileSystemObject")
'//Open page template file, read template content
Set Htmlwrite=fso. OpenTextFile (Server.MapPath ("template.htm"))
Strout=f.readall
Htmlwrite.close
strtitle= "generated page title"
strcontent= "generated Web page content"
'//Replace the tag in the template with the real content
Strout=replace (Strout, "$title $", strtitle)
Strout=replace (Strout, "$body $", strcontent)
'//Create a static page to be generated
Set Htmlwrite=fso. CreateTextFile (Server.MapPath ("test.htm"), true)
'//write page content
Htmlwrite. WriteLine Strout
Htmlwrite.close
Response.Write "Generate static page success!" "
Total 2 page: previous 1 [2] Next page