The first advantage of this technology is: (1) reduce the pressure on the database; (2) isolate the database from the page.
Then let's talk about the implementation principle ..
ASP generates HTML using the FSO built-in object on the server ..
The definition method is
Set fs = createobject ("scripting. filesystemobject") \ 'sets the FSO object
After creating a FSO object, you can manage files and folders on the server...
Therefore, it is easy to create a webpage file on the server...
Sub SaveText (FileName, Data) \ 'is a process used to write text files.
Dim fs, ts, path \ 'defines Variables
Set fs = createobject ("scripting. filesystemobject") \ 'sets the FSO object
If instr (filename, ": \") <> 0 then \ 'to determine whether it is an absolute path
Path = filename
Else
Path = server. MapPath (FileName)
End if
Set ts = fs. createtextfile (path, true) \ 'create a file object
Ts. writeline (data) \ 'Write data
Ts. close \ 'close object
Set ts = nothing
Set fs = nothing
End sub
This is a subroutine for creating the type file ..
Some comments are given to important statements...
The function is to create a file from a specified path on the server and write the data into it ..
The call method is as follows:
Savetext "D :\\\ chris.html", "chris"
You can try it on your computer ..
The first example is chris.html.
The file content is chris.
After learning how files are created, you can generate multiple web pages on the website ..
However, before generation, we must create a template for the generated page...
The following is an example ..
Mode. asp
------------------
<Body onLoad = "window. focus ();">
<Table width = "700" border = "0" align = "center" cellpadding = "0" cellspacing = "0" class = "table">
<Tr>
<Td> <br>
<Table width = "600" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td style = "LEFT: 0px; WIDTH: 600 xp; WORD-WRAP: break-word "> <p> <font size =" 2 "> <% = rs (" bigclass ") %>-> <% = rs (" smallclass ") %>-> <font color = "# FF9B9B"> <% = rs ("title") %> </font> </p>
<P> <font size = "2"> <% response. Write (ubbcode (rs ("content") %> </font> </p>
<P> </p>
<P align = "right"> <font size = "2"> from: <% = rs ("path ") %> </font> </p> </td>
</Tr>
</Table> </td>
</Tr>
<Tr>
<Td> <div align = "center"> <font size = "2"> <br>
Release date: <font color = "# FF9B9B"> <% = rs ("time") %> </font> browsing times: <font color = "# FF9B9B"> <% = rs ("browse") %> </font> </div> </td>
</Tr>
<Tr>
<Td> </td>
</Tr>
</Table>
</Body>
This is a template file ....
The following operation is to create a page to generate...
The task of generating this page is to read the file content of Mode. asp and replace it with the desired content ..
Set fso = server. CreateObject ("scripting. filesystemobject") \ 'create a FSO object
Set myfile = fso. getfile (filepath) \ 'sets a file object. filepath is the name of this template file.
Set ts = myfile. openastextstream \ 'sets a Text object and opens this object...
If not ts. atendofstream then content = changecontent (ts. readline)
Do while not ts. atendofstream
Content = content + vbcrlf
Content = content + changecontent (ts. readline)
Loop
Assign the content of the template file to the content Variable...
After processing the template content, a new webpage file is generated...
For example
Replace (content, "<% = rs (" title ") %" & ">", title)
Replace <% = Rs ("title") %> in the template file with the article title...
Other Content, Time, Browse and so on...
After the Content is processed, it is a complete webpage file ..
Output the webpage ..
Sub SaveText (FileName, Data) \ 'is a process used to write text files.
Dim fs, ts, path \ 'defines Variables
Set fs = createobject ("scripting. filesystemobject") \ 'sets the FSO object
If instr (filename, ": \") <> 0 then \ 'to determine whether it is an absolute path
Path = filename
Else
Path = server. MapPath (FileName)
End if
Set ts = fs. createtextfile (path, true) \ 'create a file object
Ts. writeline (data) \ 'Write data
Ts. close \ 'close object
Set ts = nothing
Set fs = nothing
End sub
Savetext CreateFileName, Content \ 'Call to write a file subroutine
This is basically the principle of automatic template generation...
The main problem is that you should pay attention to some details during use...
I will show you a more mature FSO demonstration program later...
Set myfile = fso. getfile (uta (filepath ))
----------------------
Create a file object based on the FSO object...
Myfile = the file you specified ..
If not ts. atendofstream then content = changecontent (ts. readline) \ 'determines whether the file is empty. if not empty, assign a value.
Do while not ts. atendofstream \ 'atendofstream determines if it is the end of the file
Content = content + vbcrlf
Content = content + changecontent (ts. readline)
Loop
The FSO object has many attributes and methods... if you are interested, refer to the VBS reference manual ..
I am only playing a guiding role here... I will explain to you how to generate a webpage file ..
Content = content + vbcrlf
Content = content + changecontent (ts. readline)
What is it?
------------------------------------
Read the file by row...
AtEndOfStream determines if it is the end of the file. Chris has already talked about it.
Do while not ts. atendofstream \ 'atendofstream determines if it is the end of the file. content = content + vbcrlf
Content = content + changecontent (ts. readline)
Loop
That is to say, read one row in the file
Just a function ..
Function uta (val)
Uta = replace (val ,"*","&")
End function
Where is filepath obtained?
Filepath is where your file is located.
15:36:19 braised rice (44018790)
Chris
What is the use of the changecontent function?
Changecontent is a function that may replace some characters in it.
There are some Replace replacement operations...
You can handle it as needed...
Not necessarily required...
The general principle is to use the FSO file creation method to create a webpage file on the server ..
Then write the code to the created file ..