(转载:www.idcew.com) ASP教程六
什么是ASP?asp基础教程 在自己电脑上运行ASP ASP基础教程二 ASP教程三 ASP页面输出到浏览器 ASP源代码可以包含程序和功能 ASP教程4 什么是Application应用程序对象 ASP教程五
#include指令 你可以插入到另一个ASP文件中的一个ASP文件的内容,然后服务器执行它,用#include指令。
#include指令用于创建功能,页眉,页脚,或将要在多个页面重复使用的元素。
如何使用#include指令 这里被称为“为MyPage.asp”的文件:
<html> <body> <h3>Words of Wisdom:</h3> <p><!--#include file="wisdom.inc"--></p> <h3>The time is:</h3> <p><!--#include file="time.inc"--></p> </body> </html>
这里是“wisdom.inc”文件: "One should never increase, beyond what is necessary, the number of entities required to explain anything."
这里是“time.inc”文件: <% Response.Write(Time) %>
如果你在浏览器的源代码,它看起来像这样:
<html> <body> <h3>Words of Wisdom:</h3> <p>"One should never increase, beyond what is necessary, the number of entities required to explain anything."</p> <h3>The time is:</h3> <p>11:33:42 AM</p> </body> </html>
语法,包括文件 要包含在一个ASP页面文件,请将#包括内部注释标签指令: <!--#include virtual="somefilename"-->
or
<!--#include file ="somefilename"-->
虚拟关键字 使用virtual关键字,表示一个虚拟目录的路径开始。
如果名为“header.inc”的文件名为/ html的虚拟目录中,下面的行会插入“header.inc”的内容:
<!-- #include virtual ="/html/header.inc" -->
该文件关键字 使用文件关键字来表示相对路径。相对路径开头的目录,包含其中的文件。
如果你有一个在html目录中的文件,该文件“header.inc”在html \头所在,下面一行会插入文件“header.inc”:
<!-- #include file ="headers\header.inc" -->
请注意,被包含文件路径(头\ header.inc)是相对于包含文件。如果该文件包含此#include语句不在html目录,该语句将不起作用
提示和注释 在上面的部分,我们使用的文件扩展名“。INC”包含的文件。请注意,如果用户试图浏览一个INC文件直接,其内容将被显示。如果您包含的文件包含机密信息或信息不希望任何用户看到的,最好是使用ASP的扩展。在ASP文件的源代码不会被解释后可见。被包含的文件还可以包含其他文件,一个ASP文件可以包含同一文件多次。
重要:包括文件处理和插入的脚本之前执行。下面的脚本将无法工作,因为ASP执行#include指令之前,分配给变量的值: <% fname="header.inc" %> <!--#include file="<%fname%>"-->
您不能打开或关闭在INC文件中的脚本分隔符。下面的脚本将不起作用: <% For i = 1 To n <!--#include file="count.inc"--> Next %>
但是,这个脚本将工作: <% For i = 1 to n %> <!--#include file="count.inc" --> <% Next %>
(转载:www.idcew.com) |