当前位置: 移动技术网 > IT编程>开发语言>Asp > asp下用实现模板加载的的几种方法总结 原创

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
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、还有一种就是把模板放到数据库中(速度慢)

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网