关于#include的补充说明

许多朋友都在问是否能动态的使用include?这在精华区中已经都有许多的篇幅说明了(关键字:include),在这里我再强调一下,

是绝对行不通的,要是使用

1if xxx = "yyy" then
1else
1end 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

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

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功能的时候,必须注意的地方。
我们可以将

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

Published At
Categories with Web编程
Tagged with
comments powered by Disqus