欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-31 21:33:04
1、使用adodb.stream实现的 一般虚拟主机都提供 复制代码 代码如下:function loadtempletfile(byval ...
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、还有一种就是把模板放到数据库中(速度慢)

上一篇:

下一篇: