There are only two main steps to generate HTML methods:
1. Get the content of the html file to be generated
2. Save the obtained html file content as an html file
What I mainly explain here is the first step: how to get the contents of the html file to be generated:
Currently, there are several common methods to obtain the content of html files:
1.
str="<html tag>content</html tag>"
str=str&"<html tag>content</html tag><html tag>database read content....</html tag>..."
This method is to write the html content to be generated in the script, which is not convenient to preview the content of the generated page, and cannot visualize the layout of the page, which will be more complicated when changing the html template.
There are many people using this method, but I feel that this method is the most inconvenient.
2. Create a separate HTML template page, use specific characters as tags for dynamic content (such as: someone uses $title$ to mark the web page title), use ADODB.Stream or Scripting.FileSystemObject to load the template content, and then use the replacement method to replace the original set tag with dynamic content
like:
Replace(loaded template content, "$title$",rs("title"))
3. Use XMLHTTP or serverXMLHTTP to obtain the HTML content displayed on the dynamic page.
I often use examples of generating html files:
'----------------------Zhai Zhenkai (Xiao Qi)
'wewebrl is the dynamic page address to obtain
'getHTTPPage(wewebrl) is a function that gets dynamic page content
weweburl="http://"&Request.ServerVariables("SERVER_NAME")&"/contact.asp?id="&rs("id")&""'Specify the dynamic page address
body=getHTTPPage(wewewebl)' Use the function to get the content of the dynamic page address
'----------------------Zhai Zhenkai (Xiao Qi)
The biggest advantage of this method is that you don’t have to work hard to write static template pages specifically, but you just convert the original dynamic pages into HTML static pages, but the generation speed is not too fast.
The third method I often use to generate HTML is: use XMLHTTP to obtain the HTML content generated by the dynamic page, and then use ADODB.Stream or Scripting.FileSystemObject to save it into an html file.
The second step is the method to generate the file:
There are two commonly used ADODB.Stream generation files and Scripting.FileSystemObject generation files in ASP.
1. Scripting.FileSystemObject file generation method:
'----------------------Zhai Zhenkai (Xiao Qi)
Setfso=CreateObject("Scripting.FileSystemObject")
File=Server.MapPath("To generate file path and file name.htm")
Settxt=fso.OpenTextFile(File,8,True)
data1="File Content" uses WriteLine method to generate files
txt.WriteLinedata1
data2="file content"' generate file using Write method
txt.Writeddata2
txt.Close
txt.fso
'----------------------Zhai Zhenkai (Xiao Qi)
2.
'----------------------Zhai Zhenkai (Xiao Qi)
DimobjAdoStream
setobjAdoStream=Server.createObject("ADODB.Stream")
objAdoStream.Type=1