There are only two steps to generate an HTML method:
1. Obtain the content of the HTML file to be generated
2. Save the obtained HTML file content as an HTML file
Here I will mainly explain the first step: how to obtain the content of the HTML file to be generated:
Currently, the following methods are commonly used to obtain HTML file content:
1,
STR = "<HTML Tag> content STR = STR & "<HTML Tag> content This method is similar to writing the HTML content to be generated in the script. It is not convenient to preview the content of the generated page, and the page cannot be visualized. It is more complicated to change the HTML template.
There are many people using this method, but I think this method is the most inconvenient.
2. Create a separate HTML template page. Dynamic Content is marked with specific characters (for example, $ title $ is used as the webpage title) and ADODB is used. stream or scripting. fileSystemObject loads the template content, and then replaces the originally set mark with dynamic content with the replacement method.
For example:
Replace (loaded template content, "$ title $", RS ("title "))
3. Use XMLHTTP or serverxmlhttp to obtain the HTML content displayed on the dynamic page,
Examples of commonly used HTML file generation:
'--------------- Xiao zhenkai (Xiao Qi)
'Weburl is the dynamic page address to be obtained
'Gethttppage (weburl) is a function for retrieving dynamic page content.
Weburl = "http: //" & request. servervariables ("SERVER_NAME") & "/contact. asp? Id = "& RS (" ID ") &" "'specifies the dynamic page address
Body = gethttppage (weburl) 'Use the function to get the content of the dynamic page address
'--------------- Xiao zhenkai (Xiao Qi)
The biggest advantage of this method is that you do not need to write static template pages, but convert the original dynamic pages to HTML static pages, but the generation speed is not too fast.
I often use 3rd HTML generation methods: Use XMLHTTP to get the HTML content generated by dynamic pages, and use ADODB. Stream or scripting. FileSystemObject to save it as an HTML file.
The second step is to generate the file:
Commonly used files in ASP are ADODB. Stream and scripting. FileSystemObject.
1. Scripting. FileSystemObject file generation method:
'--------------- Xiao zhenkai (Xiao Qi)
Set FSO = Createobject ("scripting. FileSystemObject ")
File = server. mappath ("to generate a file catalog and file name .htm ")
Set TXT = FSO. opentextfile (file, 8, true)
Data1 = "file content" use writeline to generate a file
TXT. writeline data1
Data2 = "file content" 'Use the write method to generate a file
TXT. Write data2
TXT. Close
TXT. FSO
'--------------- Xiao zhenkai (Xiao Qi)
2,
'----------------- Xiao zhenkai (Xiao Qi)
dim objadostream
set objadostream = server. createobject ("ADODB. stream ")
objadostream. type = 1
objadostream. open ()
objadostream. write ("file content")
objadostream. savetofile: generate the file principal and file name .htm, 2
objadostream. close ()
'--------------- Xiao zhenkai (Xiao Qi)