首页 > 计算机应用 > ASP页面批量生成HTML的两种方法

ASP页面批量生成HTML的两种方法

      方法一生成HTML的速度比较慢,方法二较快,但是耗费更多CPU。
      方法一程序代码:

复制内容到剪贴板程序代码程序代码
<!#include file="conn.asp">
<HTML><HEAD><TITLE>生成页面</TITLE>
<META httpequiv=ContentType c>
<LINK href=http://www.chinaz.com/Program/Asp/"style.css" type=text/css rel=stylesheet>
<META c name=GENERATOR>
</HEAD>
<BODY bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0>
<BR style="OVERFLOW: hidden; LINE-HEIGHT: 3px">
<%
dim id
id=cint(request.querystring("id"))
if id="" then
id="1"
else
id=cint(request.querystring("id"))
end if
Dim totalnumber
sql="select id from table order by id DESC"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
rs.Movefirst
if not rs.eof then
TotalNumber=rs.recordcount
end if
获取总数可以用一句代码代替,这个相信朋友自己可以解决.
rs.close
set rs=nothing
Response.Write "<br><br>" & vbNewLine
Response.Write "<table width='400' border='0' align='center' cellpadding='0' cellspacing='0'>" & vbNewLine
Response.Write "  <tr>" & vbNewLine
Response.Write "    <td height='50'>总共 <font color='blue'><b>" & totalnumber & "</b></font> 个页面,正在生成第 <font color='red'><b>" & ID & "</b></font>  个页面…… </td>" & vbNewLine
Response.Write "  </tr>" & vbNewLine
Response.Write "</table>" & vbNewLine
Response.Flush

If ID > totalnumber Then
Response.Write "恭喜您操作成功!"
Response.Flush
End If Www_Chinaz_com

creat(ID)
id=id+1
Response.Write "<meta http-equiv=""refresh"" c&id&""">"
%>
</BODY>    
</HTML>
<%
Function creat(id)
sql="Select * from table where id="&ID

set
rs=conn.execute(sql)
dim name
name=rs("name")
conn.execute(sql)
rs.close
set rs=nothing
dim fso
dim znwl
dim art
dim fw
set fso=createobject("scripting.filesystemobject")
set znwl=fso.opentextfile(server.mappath("模板页"))
art=znwl.readall
znwl.close

Chinaz_com

art=replace(art,"{$name$}",name)
set fw=fso.createtextfile(server.mappath("生成页存放位置及页面名称"),true)
fw.writeline art
fw.close
set fso=nothing
End Function
%>

方法二比方法一生成静态页面的速度快,但是占用CPU比较多,代码如下:

方法二程序代码:

复制内容到剪贴板程序代码程序代码
<!#include file="conn.asp">
<HTML><HEAD><TITLE>生成页面</TITLE>
<META httpequiv=ContentType c>
<LINK href=http://www.chinaz.com/Program/Asp/"style.css" type=text/css rel=stylesheet>
<META c name=GENERATOR>
</HEAD>
<BODY bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0>
<BR style="OVERFLOW: hidden; LINE-HEIGHT: 3px">
<table border="1" width="100%" id="table1">
<tr>
  <td>
<%
dim allid,ppp,id,totalnum
sql="select * from table order by id DESC"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof        
   if allid="" then allid= rs("id") else allid= allid & ";" & rs("id")      
   rs.movenext      
loop
else
   If Rs.bof And Rs.EOF Then
   Response.Write "还没有找到任何文章!"
   End if

end if
rs.close
set rs=nothing

allid=";"+allid
ppp=split(allid,";")
totalnum=ubound(ppp)
for id=1 to totalnum
Session("id")=Session("id")+1
creat(id)
response.write "正在生成znwl_"&id&".htm…<br>"
next
%>
 </td>
</tr>
</table>
</BODY>    
</HTML>

<%
Function creat(id)
sql="Select * from table where id="&ID
set rs=conn.execute(sql)
dim name
name=rs("name")
conn.execute(sql)
rs.close
set rs=nothing
dim fso
dim znwl
dim art
dim fw
set fso=createobject("scripting.filesystemobject")
set znwl=fso.opentextfile(server.mappath("模板页"))
art=znwl.readall
znwl.close
%>

art=replace(art,"{$name$}",name)
set fw=fso.createtextfile(server.mappath("生成页存放位置及页面名称"),true)
fw.writeline art
fw.close
set fso=nothing
End Function

转载请尊重版权,出处:秋天博客
本文链接: https://www.cfresh.net/pc-tech/540

  1. 还没有评论
评论提交中, 请稍候...

留言



注意: 您给他人的评论回复将通过邮件通知到对方。

可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks