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>
相关文章
- msxml3.dll错误'800c0005'系统错误: -2146697211 2012-01-04
- [转载] Response.CharSet 2008-06-24
- asp脚本运行超时的解决办法 2008-10-27
- asp库没有注册的解决方案 2008-12-04
- asp和access的一些安全问题 2008-10-30
- 纯css+html制作的菜单 2008-07-06
- xhtml+css 设计注意事项 2008-07-30
- 从HTML到XHTML需要注意的基本准则 2008-06-17
- 一个不错的菜单特效 2008-07-06
- W3C公布HTML5的WEB标准草案 2008-07-29
- 动态网址与静态网址 2008-10-28
- 网站静态化策略 2009-01-28