Asp生成静态页的方法总结

 
1:模板替换方法
       原理就是做一个模板文件放到目录里或将模板文件的代码保存到数据库里,当添加、修改数据或者批量生成的时候用FSO读取模板文件的内容,将其中的特殊字符替换成相应的内容然后写成一个文件保存到目录里就可以了。
2:用xmlHttp对象读取动态执行结果
做好前台的动态页面,页面需要传入一个参数以便到数据库中读取相应的内容,当添加、修改数据或者批量生成的时候用函数读取动态页面执行后的页面内容,然后写成一个文件保存到目录里就可以了。
Function GetPage(url)
       'On Error Resume Next
       dim Retrieval
       Set Retrieval = CreateObject("Microsoft.XMLHTTP")
       With Retrieval
       .Open "Get", url, False ', "", ""
       .Send
      
       GetPage = BytesToBstr(.ResponseBody)
       End With
       Set Retrieval = Nothing
End Function
 
Function BytesToBstr(body)
       dim objstream
       set objstream = Server.CreateObject("adodb.stream")
       objstream.Type = 1
       objstream.Mode =3
       objstream.Open
       objstream.Write body
       objstream.Position = 0
       objstream.Type = 2
       objstream.Charset = "GB2312"
       BytesToBstr = objstream.ReadText
       objstream.Close
       set objstream = nothing
End Function
       3:在多行文本框里执行动态模板页面
       让动态文件的执行结果放到多行文本框里并使其隐藏,将其做为表单内容提交,在处理程序中将接收到的文件内容写成一个文件存放到目录里。这种方法比较适合于不用接受参数的动态页面,比如友情链接、产品中心等。
     <Form name="go" method="POST" action="default.asp">
      <td width="132">
        <table width="100%" border="0">
          <tr>
            <td><input type="submit" style="width:120" name="Submit" value="点击生成友情链接页"></td>
          </tr>
          <tr style="display:none">
            <td><textarea name="word" id="word"><!--#include file="../../link_w.asp"--></textarea></td>
          </tr>
        </table>
       
      </td>
    </FORM>
<%
filename="../../link_w.html"
if request("word")<>"" then
set fso = Server.CreateObject("Scripting.FileSystemObject")
set fout = fso.CreateTextFile(server.mappath(""&filename&""))
fout.write request.form("word")
fout.close
set fout=nothing
set fso=nothing
response.write "生成文字链接页成功!<a href=../../link_w.html target=blank>查看</a>"
end if
%>
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值