ASP动态包含文件问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 00:55:01
我在处理包含文件的问题时使用了如下函数
Function include(filename)
Dim re,content,fso,f,aspStart,aspEnd
set fso=CreateObject("Scripting.FileSystemObject")
set f=fso.OpenTextFile(server.mappath(filename))‘此处为190行
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
response.Write(aspEnd)
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("filename.asp")调用函数

但使用这个函数包含一个文件时,提示如下错误
Microsoft VBScript 运行时错误 '800a0005'

如果标记符<%%>内的内容是
<%@LANGUAGE="JavaScript" CODEPAGE="65001"%>之类的,那么这行代码只能放在asp的头部执行,所以无法被其他文件包含,不管使用你的函数包含还是使用<!--#...-->来包含都会出错
如果<%%>标记符内只是普通的asp代码,那么你可以把html代码都转为asp,然后全部放入一个标记符内,
另外值得注意的是,当你使用你的include函数包含其他文件的时候,被包含的文件内绝对不能再包含其他的文件,否则一定出错。

既然知道错误的原因,那就在使用正则前,先把<% %>用REPLACE替换掉。

Maxthon,还有其他一些浏览器的“上次访问的页面”里表里其实存放的是过去的页面地址,建议你使用IE浏览。