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

ASP
asp 网站静态化函数代码html
asp利用Split函数进行多关键字检索
ASP动态include文件
用ASP开发网页需要牢记的注意事项
利用ASP发送和接收XML数据的处理方法
Session对象失效的客户端解决方法
一次性下载远程页面上的所有内容
asp模板引擎终结者(WEB开发之ASP模式)
浅谈 ASP 模板技术之参数传递
本人常用的分页代码
也谈采集入库的技术
简单分页函数一 常用
msxml3.dll 错误 ''800c0005''解决方案
[原创]本人常用的asp代码
生成所有页面的效果+分页生成
[原创]关于Script的Defer属性
[原创]asp截取字符串的两种应用
内容分页函数
[ASP]精华代码
asp提高首页性能的一个技巧

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 80 ::
收藏到网摘: 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、还有一种就是把模板放到数据库中(速度慢)