当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP批量生成静态页

ASP
ASP实现表单中容量大的数据的提交方法
强烈推荐ASP初学者观看:常用ASP技术
认真学习ASP内置对象Session的应用
asp函数转换xml中的实体字符[转义符]
ASP防止重复多次提交表单的方法
ASP处理XSLT转换XML的实现
ASP中将Excel数据导入到Access
[推荐]ASP 编程中 20 个非常有用的例子
[推荐]每个ASP程序员必备的知识
[推荐]ASP初学者常犯的几个错误
解决杀毒软件误删asp文件的方法
用VB编写ActiveX DLL实现ASP编程
asp.net结合js的网页打印程序
ASP网站远程客户实现EXCEL打印功能
ASP程序中使用断开的数据记录集
利用ASP发送和接收XML数据的处理方法
20种看ASP程序源码的方法及工具
ASP技巧:禁用FileSystemObject组件
在ASP中使用SQL语句:开始执行
ASP编写计数器的优化方法

ASP批量生成静态页


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 79 ::
收藏到网摘: n/a

由于本人的空间收到限制,不能一次批量生成所有的静态页,所以自己写了一个小程序和大家分享,程序相当简单,高手莫要见笑!此代码就是很浪费时间.代码如下

<!--#include file="conn.asp"-->
<HTML><HEAD><TITLE>生成页面</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="style.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3020" 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

creat(ID)
id=id+1
Response.Write "<meta http-equiv=""refresh"" content=""1;url=?ID="&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

 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 http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="style.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3020" 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


这种方法快,但是你的空间要不受限制!--智能网络

上面的方法仅供参考,并不是本人修改的最后版本,但是绝对好用.