How to generate static html pages for ASP website? I believe there are still many friends who don’t know this technique. So now we will follow the editor of Cuoxin to study and study together. I hope it will be helpful for you to learn Asp.
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 generates file method:
'----------------------Zhai Zhenkai (Xiao Qi)
Set fso = CreateObject("Scripting.FileSystemObject")
File=Server.MapPath("To generate file path and file name.htm")
Set txt=fso.OpenTextFile(File,8,True)
data1="File Content" uses WriteLine method to generate files
txt.WriteLine data1
data2="file content"' generate file using Write method
txt.Write data2
txt.Close
txt.fso
'-----------------------Zhai Zhenkai (Xiao Qi)
2.
'----------------------Zhai Zhenkai (Xiao Qi)
Dim objAdoStream
set objAdoStream = Server.createObject("ADODB.Stream")
objAdoStream.Type = 1
objAdoStream.Open()
objAdoStream.Write("File Content")
objAdoStream.SaveToFile to generate file path and file name.htm,2
objAdoStream.Close()
The above is an introduction to the tips for generating static html pages on ASP websites. Do you have any understanding after reading it? If you have any questions, you can leave a message to communicate.