ASP生成静态HTML页面

日期:2011-09-25    阅读:122   分类:综合信息


网站静态化已经是一个老生常谈的话题了,在asp,php,java,.net等web后端开发语言都会用到。那么下面贴一个使用asp生成静态html的一个代码:

先看调用方法:

<%
MakePage "/tmp/index.asp", "/index"

'上面代码就会访问把index.asp返回的html写入到站点根目录的index文件,调用非常简单,也比较通用。
%>

' <summary>
' 生成页面
' </summary>
'<param name="source">原始页面</param>
'<param name="target">目标页面</param>
Sub MakePage(source ,target)
    Dim ex ,data ,host
    host = Request.ServerVariables("HTTP_HOST")
    Set ex = CreateComponent("SL.Remote")
    ex.Location = "http://"& host & source
    data = ex.GetData()
    ex.Dispose
    Set ex =Nothing

    Dim fso ,ftxt
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    Set ftxt = fso.CreateTextFile(Server.MapPath(target) ,true)
    ftxt.write data
    ftxt.close

    Set ftxt = Nothing
    Set fso = Nothing
End Sub

SL.Remote的代码:

<?xml version="1.0" encoding="utf-8"?>
<package>
<?component error="false" debug="false"?>
<comment>
<![CDATA[
    '/**************************************************
    ' * 远程调用模块
    ' * 2009-1-17
    '**************************************************/
]]></comment>
<scriptlet id="Remote">
<registration clsid="{12345678-aabb-ccdd-eeff-012345678909}" progid="SL.Remote" version="3.3" description="远程调用模块" />
<public>
    <property name="Location" />
    <property name="Parameter" />
    <method name="Dispose" />
    <method name="GetData" />
</public>
<implements type="ASP" />
<script language="Vbscript">
<![CDATA[
' <summary>
' 远程地址
' </summary>
Public Location

' <summary>
' 参数
' </summary>
Public Parameter

' <summary>
' XMLHTTP对象
' </summary>
Private XMLHttp

' <summary>
' 类注销
' </summary>
Public Sub Dispose
    Set XMLHttp = Nothing
End Sub

' <summary>
' 获取数据
' </summary>
Public Function GetData()
    Set XMLHttp = Server.CreateObject("Microsoft.Xmlhttp")
    XMLHttp.open "get" ,Location ,False
    XMLHttp.send
    GetData = Bytes2Bstr(XMLHttp.responseBody ,"gb2312")
End Function

' <summary>
' 获取数据
' </summary>
Private Function Bytes2Bstr(content ,charset)   
    Dim Stream
    set Stream = Server.CreateObject("adodb.stream")
    Stream.Type = 1
    Stream.Mode =3
    Stream.Open
    Stream.Write content
    Stream.Position = 0
    Stream.Type = 2
    Stream.Charset = charset
    Bytes2Bstr = Stream.ReadText
    Stream.Close
    Set Stream = Nothing
End Function
]]>
</script>
</scriptlet>
</package>

本页链接: http://www.scriptlover.com/static/940-asp-html-静态

标签:

相关文章

网友评论

Leave a comment

 required

 required (Not published)

 required