热门文章
 
ASP内建对象Server
Global.asa文件的使
ASP内建对象Applica
访问和更新Cookies集合
Asp:Cookie集合 简
asp中cookie使用示例
Asp:Cookie集合简介
遍历cookies的方法
判断cookie是否开启
cookies读写基本例子
 推荐文章
 
ASP Session 对象
松子谈asp的Request
再总结一下asp重定向的方法
asp:Session St
session的使用与性能:
asp session 使用
asp中session具体是
防止ASP Session丢
Asp提高首页性能的一个技巧
ASP禁止刷新当前页
asp清空session 关
TypeLibrary 声明
cookies和sessio
web开发:Session详
ASP中Session技巧
再谈asp中的Server.
 
你现在的位置:您现在的位置是: 中国ASP>>ASP教程>>ASP对象
动态include

受<! #include file="filename.asp" --> 宏限制
必须存在该文件并且会预先编译(不管前面是否加以条件)

经常有这样的要求,根据不同的需求要求include不同的文件
如各个人的不同设置,所以要求能动态include文件。

代码如下:

Function include(filename)
Dim re,content,fso,f,aspStart,aspEnd

set fso=CreateObject("Scripting.FileSystemObject")
set f=fso.OpenTextFile(server.mappath(filename))
content=f.ReadAll
f.close
set f=nothing
set fso=nothing

set re=new RegExp
re.pattern="^\s*="
aspEnd=1
aspStart=inStr(aspEnd,content,"<%")+2
do while aspStart>aspEnd+1
Response.write Mid(content,aspEnd,aspStart-aspEnd-2)
aspEnd=inStr(aspStart,content,"%\>")+2
Execute(re.replace(Mid(content,aspStart,aspEnd-aspStart-2),"Response.Write "))
aspStart=inStr(aspEnd,content,"<%")+2
loop
Response.write Mid(content,aspEnd)
set re=nothing
End Function

使用范例:

include("youinc.asp")

相关信息:

ASP内建对象Server
include:服务器端包含
Server对象的错误处理
Server对象:数据格式化
ASP Server对象
asp:Server对象
动态include
使用 Server.Transfer
Server.Transfer 和Response.Redirect 比较

 

中国ASP技术 ASP.ORG.CN 版权所有 2004-2008