ASP批量生成靜態頁_ASP教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:學ASp動態網頁必備:常用的38個函數
      1.函數array()  功能:創建一個數組變量  格式:array(list)  參數:list 為數組變量中的每個數值列,中間用逗號間隔  例子:  <% i = array ("1","2","3&quo

      由于本人的空間收到限制,不能一次批量生成所有的靜態頁,所以自己寫了一個小程序和大家分享,程序相當簡單,高手莫要見笑!此代碼就是很浪費時間.代碼如下

      <!--#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


      這種方法快,但是你的空間要不受限制!--智能網絡

      上面的方法僅供參考,并不是本人修改的最后版本,但是絕對好用.

      分享:ASP技巧實例:幾行代碼解決防止表單重復提交
      在很多情況下都需要防止相同的表單被多次提交,很多人的實現方法都比較復雜(代碼數量超過幾十行!)下面提供一種只需使用幾行代碼的方法,輕松地實現了防止用戶刷新多次提交表單和使用后退鈕重

      來源:模板無憂//所屬分類:ASP教程/更新時間:2008-08-22
      相關ASP教程