WEB开发网
开发学院WEB开发ASP 关于#include的补充说明 阅读

关于#include的补充说明

 2002-09-18 10:23:39 来源:WEB开发网   
核心提示:许多朋友都在问是否能动态的使用include?这在精华区中已经都有许多的篇幅说明了(关键字:include),在这里我再强调一下,关于#include的补充说明,<!--#include file="<%fileName%>"-->是绝对行不通的,要是使用<%if xx
许多朋友都在问是否能动态的使用include?这在精华区中已经都有许多的篇幅说明了(关键字:include),在这里我再强调一下,<!--#include file="<%fileName%>"-->是绝对行不通的,要是使用
<%if xxx = "yyy" then%>
<!--#include file="file1.asp"-->
<%else%>
<!--#include file="file2.asp"-->
<%end if%>
这无形中会下载没有必要的档案,影响载入网页的速度。如何解决这个问题呢?在精华区中的
1)http://www.dev-club.com/club/bbs/showEssence.asp?id=14354
2)http://www.dev-club.com/club/bbs/showEssence.asp?id=5246&page=1
都做得很好的说明,在这里我不想重复。这些方法有:

1)
If xxx = "yyy" Then
 Server.Execute("file1.asp")
Else
 Server.Execute("file2.asp")
End If

2)
If xxx = "yyy" Then
 Server.transfer("file1.asp")
Else
 Server.transfer("file2.asp")
End If

3)
if xxx = "yyy" then
filespec = "file2.asp"
else
filespec = "file2.asp"
end if
filespec = server.mapPath(filespec)
scr = "scripting.fileSystemObject"
set fs = server.createobject(scr)
set f = fs.openTextFile(filespec)
content = f.readall
set f = nothing
set fs = nothing
response.write(content)

我要说明的就是,如果使用以上方法来实现include功能的时候,必须注意的地方。
我们可以将<!--#include file="file.asp"-->中被包含的网页file.asp看成是包含了file.asp的网页的有机组成部分,只是将本来属于该网页的内容以另一个档案形式保存罢了,可以这样说他们本来就是一个网页,所以,被包含的网页file.asp继承了包含了file.asp的网页的所有的参数设定,包括session 但是,其他的方法并非如此,在html语法部分可以和主网页共享,asp部分却是独立的,特别的Session在一般情况下是不能从主网页中传递到被包含的网页file.asp来,这点很重要,使用时要注意。

Tags:关于 include 补充

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接