当前位置: 首页 > 图文教程 > 网络编程 > ASP > [原创]asp下用实现模板加载的的几种方法总结

ASP
ASP编程中15个非常有用的例子 (二)
ASP与JSP的比较(一)
ASP与JSP的比较(二)
ASP中五种连接数据库的方法
从ASP调用SQL中的图像
用排序串字段实现树状结构(例程:连接字串)
用排序串字段实现树状结构(例程:删除贴子)
用排序串字段实现树状结构(例程:回复表单)
用排序串字段实现树状结构(例程:显示贴子内容)
用排序串字段实现树状结构(例程:显示树)
用排序串字段实现树状结构(存储过程)
用排序串字段实现树状结构(库结构)
用排序串字段实现树状结构(原理)
remote script文档(转载自微软)(一)
remote script文档(转载自微软)(二)
remote script文档(转载自微软)(三)
remote script文档(转载自微软)(四)
remote script文档(转载自微软)(五)
remote script文档(转载自微软)(六)
remote script文档(转载自微软)(七)

ASP 中的 [原创]asp下用实现模板加载的的几种方法总结


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 141 ::
收藏到网摘: n/a

asp下html模板的加载方法,一般有以下几种,大家可以根据情况自己决定,结果都是一样的,都是好方法 1、使用adodb.stream实现的 一般虚拟主机都提供
复制代码 代码如下:

function loadtempletfile(byval path)
on error resume next
dim objstream
set objstream = server.createobject("adodb.stream")
with objstream
.type = 2
.mode = 3
.open
.loadfromfile server.mappath(path)
if err.number <> 0 then
err.clear
response.write("预加载的模板[" & path & "]不存在!")
response.end()
end if
.charset = "" & chrset & ""
.position = 2
loadtempletfile = .readtext
.close
end with
set objstream = nothing
end function

2、用fso实现模板的加载速度快,但好多虚拟主机不提供fso功能
复制代码 代码如下:

'*******************************************************************************************************
'函数名:LoadTemplate
'作 用:取出模板内容
'参 数:TemplateFname模板地址
'返回值:模板内容
'********************************************************************************************************
Function LoadTemplate(TemplateFname)
on error resume next
Dim FSO, FileObj, FileStreamObj
Set FSO = CreateObject("scripting.filesystemobject")
TemplateFname = Server.MapPath(Replace(TemplateFname, "//", "/"))
If FSO.FileExists(TemplateFname) = False Then
LoadTemplate = "模板不存在,请先绑定!"
Else
Set FileObj = FSO.GetFile(TemplateFname)
Set FileStreamObj = FileObj.OpenAsTextStream(1)
If Not FileStreamObj.AtEndOfStream Then
LoadTemplate = FileStreamObj.ReadAll
Else
LoadTemplate = "模板内容为空"
End If
End If
Set FSO = Nothing:Set FileObj = Nothing:Set FileStreamObj = Nothing
LoadTemplate=LoadTemplate & Published
End Function
'**************************************************

ASP使用FSO读取模板的代码
3、还有一种就是把模板放到数据库中(速度慢)