百度空间 | 百度首页 
 
查看文章
 
ASP生成Html函数,不用模板
2009-09-07 07:34
ASP生成Html函数,不用模板
2009年02月16日 星期一 上午 00:16

<%
Function MakeHtml(strURL,strTo)
   on error resume next
   response.write "开始生成静态页面..."
   strHtml = GetPage(strURL)
   
   Set fs=Server.CreateObject("Scripting.FileSystemObject")
   '要存放的页面地址
   strAddress=server.MapPath(strTo)
   '如果文件存在则删除旧文件
   If (fs.FileExists(strAddress)) Then fs.DeleteFile(strAddress)
   
   Set mHtml=fs.CreateTextFile(strAddress)
   mHtml.Writeline(strHtml)
   set mHtml=nothing
   set fs=nothing
   response.write "...<font color=red>生成静态页面<"&strTo&">成功!</font>"  
End Function

'######获取要生成动态页地址######
Function GetPage(url)
    '获得文件内容
    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 = "GBK"
    BytesToBstr = objstream.ReadText
    objstream.Close
    set objstream = nothing
End Function
%>

保存为MakeHtml.inc.asp

使用方法:

      在要实现生成静态功能的页面头部添加

      <!--#include file="<你存放的路径>/makehtml.inc.asp"-->

      在需要调用生成静态页面的地方添加

      MakeHtml “http://localhost/index.asp","/index.html"

      上面的路径换成你自己的,这样即可无模板生成静态页面。不过这种方法比较耗资源,生成速度慢,但是简单易上手。


类别:网络程序 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu