This is my first time writing an article in CSDN. My literary talent and theoretical knowledge are limited. I welcome corrections if I write incorrectly. In fact, there are already many articles about ASP generating HTML on the Internet. One method is the ASP+XML generation method. Although one advantage is that you can directly reference the original source code of the page to be generated without writing a template with a program, but I tested this method. At that time, I found that its stability was poor and its network speed requirements were high (of course it was not on the server). Especially in the virtual space, errors are often reported. It may be due to my insufficient code processing in this method. To make a long story short, this article uses another commonly used method ASP+FSO. The framework is also used here to reduce the generation time when processing a large number of paging. This method is for some ASP files with large page volumes.
Here I quote a simple example: (travel e-commerce) hotel application static pages (htm) in major cities across the country are displayed in paging
1. Application system environment: win2000+ASP+MSSQL/ACCESS (the database is basically irrelevant)+iis5. 0
2.1 city lists (CityHtml): including three fields defining static html names (city ID (automatic number), city name (CityName such as Beijing), generated html prefix name (HtmlStartName such as beijing))
3.1 national hotel lists ( Hotel): Here I only create three fields (hotel ID (automatic number), city name (City), hotel name (HotelName)) to facilitate reference to the instance.
4.1 ASP pages (ToHtm.asp) (used to generate htm)
5.1 loop frame pages (IframeToHtm.asp), application framework to batch generate htm.
The following is the source code of two pages of
loop frame for batch generation of pages: IFrameToHtm.asp
< !--#include file="conn.asp"-->'Connect to the database
<%
dimrs,sql,j
set rs=Server.CreateObject("adodb.recordset")
sql="select * from CityHtml"'Open the list of cities across the country
rs.open sql,conn,1,1
do until rs.eof' loop through major cities%>
<!--The following application framework opens the ToHtml generated page-->
<IFRame name="LoadRcHtm<%=j%>" frameborder=0 width=100% height=30 scrolling=no src="ToHtml.asp?City=<%=cstr(rs("city"))%>&HtmlStartName =<%=rs("HtmlStart")%>"></IFrame>
<%rs.movenext
loop%>
Generate program page: ToHtm.asp I probably write a comment in the source code **
<!--#include file="conn.asp"-->'data connection file
<%
On Error Resume Next'Fault tolerance processing
Dim City' definition gets the city to generate the page
City=Request.Querystring("City")' Gets the generated city hotel value passed from the framework, which will be introduced later
HtmlStartName=Request.Querystring("HtmlStartName")'Get the generated html file name prefix
Dim sql' search string, here I will open the table directly without searching for variables, just write the search conditions yourself.
sql="select * from Hotel where [City] = '" & City & "' "
Dim oRs' data operation object
Dim PageCounts'To implement paging generation, you must know how many pages there are
Set oRs = Server.CreateObject("ADODB.Recordset")
oRs.Open Sql,oConn,1,1'Find the table that opens the hotel equal to the City variable
oRs.pagesize=10'Ten records are one page
PageCounts=oRs.pagecount' to get how many pages to generate, use it in a loop to generate
Dim fs' defines fso file object
Dim folders' the name of the folder where static pages are stored
Dim Filestart' defines the prefix for generating htm files
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Dim i
for i=1 to PageCounts' starts to generate pages in a loop, that is, paging is generated.
page=i
oRs.absolutepage=i'page number
rowcount=oRs.pagesize'Number of records on the current page
folders=server.mappath("CityHtml")
if (fs.FolderExists(folders)) then' determine whether the folder exists
else
fs.CreateFolder(folders)' creates the CityHtml folder if it does not exist
end if
if i=1 then
Filestart=HtmlStartName'If it is the first page, define the file name and pass the value name. For example, beijing is beijing.htm
else
Filestart=HtmlStartName&i'If the second page is beijing+1, for example, if there are two pages, i equals 2, then it is beijing2.htm and so on...(.htm suffix is added at the end)
end if
Dim files' defines the generated text file name variable
Dim filez'define file path name variable
files=Filestart&".txt"'name of this file
filez=folders&""&"files' text file path
'Delete files
Dim checkfile'checks whether the text file already exists, if so delete it
checkfile=server.mappath("CityHtml"&Filestart&".htm")'Check whether the htm file already exists, if so, delete it
if (fs.FileExists(checkfile)) then'Check whether the htm file already exists, if so, delete it
Dim df'define file object *delete file using*
Set df=fs.GetFile(checkfile)'define the file to be deleted
df.delete' delete file
end if'end of judgment
Dim ts' defines writing file object
set ts = fs.createtextfile(filez,true) 'Enable writing file content**I just simply write the hotel name and static number paging display in the text**
ts.write("<Html><Head><Title>Generate"&City&"City Hotel</Title>"&vbcrlf)' After that, the content of the main file is to be generated and use Response.write
ts.write("<META http-equiv=Content-Type content=text/html; charset=gb2312>"&vbcrlf)
ts.write("<meta name=keywords content="&city&"hotel>"&vbcrlf)
ts.write("<link href='/Style/style.css' rel='stylesheet' type='text/css'></head><body topmargin=0>"&vbcrlf)
ts.Write("<TABLE WIDTH=760 cellspacing=0 cellpadding=0 align=center>"&vbcrlf&_
"<TR><TD width='100%'>"&vbcrlf)
'Start paging output
'I won't go into details about the principle of digital paging program here. Friends who don't understand can search it on the Internet.
Dim page' current page
Dim Page2'Digital paging variable
Dim s' digital pagination variable
if page=1 then
ts.write (" [Home] [Previous Page] ")
else
ts.write (" <a href="&HtmlStartName&".htm"&" class=blue>[Home]</a> <a href="&HtmlStartName&Replace(page-1,1,"")&".htm"& " class=blue>Previous page</a> ")
end if
page2=(page-(page mod 10))/10
if page2<1 then page2=0
for s=page2*10-1 to page2*10+10
if s>0 then
if s=cint(page) then
ts.write (" <font color='#000000'>["& s & "]</font>")
else
if s=1 then
ts.write (" <a href="&HtmlStartName&replace(s,1,"")&".htm"&" class=blue>["& s &"]</a>")
else
ts.write (" <a href="&HtmlStartName&s&".htm"&" class=blue>["& s &"]</a>")
end if
end if
if s=ors.pagecount then
exit for
end if
end if
next
if cint(page)=ors.pagecount then
ts.write ("[next page] [last page]")
else
ts.write (" <a href="&HtmlStartName&page+1&".htm"&" class=blue>[next page]</a> <a href="&HtmlStartName&ors.pagecount&".htm"&" class=blue> [Last page]</a>")
end if
ts.write("</TD></TR>")
'End of paging output
do while not ors.eof and rowcount>0 'Output hotel name
ts.write("<TR><TD width='100%'>"&oRs.Fields("Chinese_Name")&"</TD></TR>"&vbcrlf)
oRs.movenext
rowcount=rowcount-1'When the number of records on the page is -1 loop
ts.write("</Table></body></html>"&vbcrlf)
ts.close
set ts=nothing 'Release object
Dim EditFile' defines rewriting file variables
Set EditFile = fs.GetFile(filez)'Set the rewrite file object
EditFile.name= left(EditFile.name,len(EditFile.name)-4)&".htm" 'Rewrite the text file into htm
next' loop generation ends (paging generation)
set EditFile=nothing 'Release object
set fs=nothing'release the object
if err.number<>0 then 'Handle generated errors
Response.write(City&"An unknown error occurred while updating <A href=ToHtml.asp?City="&City&"&HtmlName="&HtmlStartName&">Re-update</A>")
else
Response.Write(City&"Hotel update completed"&Now())
end if
%>