The webpage generates static Html file to have a lot of profit, generate Html webpage to be helpful for be being collected by search engine for instance, what be collected not only is fast what still collect is complete. Broke away from data visit downstage, ease the pressure that visits to the database, accelerate a webpage to open career.
1, this example uses FSO to write Html code into the file that makes.html form next in the file directly below
<%
Filename=”test.htm “
If Request("body")<>"" Then
Set Fso = Server.CreateObject(”Scripting.FileSystemObject” )
Set Htmlwrite = Fso.CreateTextFile(server.mappath(""&filename&"") )
Htmlwrite.write "<html><head><title> "&Request.form(”title” )&"</title></head> "
Htmlwrite.write "<body> outputs Title content: Htmlwrite.write “
outputs Title content:: &Request.form(”title” )&"<br /> outputs Body content:" &Request.form(”body” )&"</body></html> "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=" generates Html">
</form>
2, but make Html file according to the method above special inconvenience, the 2nd kind of method uses pattern plate technology namely, replace the cost of special code in pattern plate for from express sheet or be a database the value that come over is accepted in the field, the code of all pattern plate that; of function of the pattern plate that finish will replaced finally makes HTML file. This kind of technology is used morer, major CMS is to use this kind of method.
Template.htm ‘ / / pattern plate file
<html>
<head>
<title>$title$ By Aspid.cn</title>
</head>
<body>
$body$
</body>
</html>TestTemplate.asp ‘ / / generate Html
<%
Dim Fso, htmlwrite
Dim StrTitle, strContent, strOut
‘ / / establish file system target
Set Fso=Server.CreateObject(”Scripting.FileSystemObject” )
‘ / / open file of webpage pattern plate, read take pattern plate content
Set Htmlwrite=fso.OpenTextFile(Server.MapPath(”Template.htm”) )
StrOut=f.ReadAll
Htmlwrite.close
The webpage headline that StrTitle=” makes ”
The webpage content that StrContent=” generates ”
‘ / / the mark in replacing pattern plate with true content
StrOut=Replace(strOut, “$title$” , strTitle)
StrOut=Replace(strOut, “$body$” , strContent)
‘ / / found the static page that should make
Set Htmlwrite=fso.CreateTextFile(Server.MapPath(”test.htm”) , true)
‘ / / keep webpage content
Htmlwrite.WriteLine StrOut
Htmlwrite.close
Response.Write ” makes static page success! Response.Write ” makes static page success!!
‘ / / release file system object
Set Htmlwrite=Nothing
Set Fso=Nothing
%>
In all 2 pages: On one page 1[2] Issue one page
