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

ASP
ASP中通过该日历算法实现的具体代码
ASP类编写详细说明
一个简单的asp数据库操作类
一个asp快速字符串连接类
ByVal和ByRef(编写ASP子程序所用到命令)
FSO一些代码
ASP连接11种数据库语法总结
代码与页面的分离
ASP 类专题
直接保存URL图像或网页到服务器本地的类
[原创]关于Script的Defer属性
[ASP]使用类,实现模块化
在VBScript中使用类
浅谈ASP中的类
ASP中一个用VBScript写的随机数类
文件、目录,文本文件等多种操作类
Object对象的一些的隐藏函数介绍
ASP高亮类
叶子asp分页类
遭遇ASP类的事件设计

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


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