码迷,mamicode.com
首页 > Web开发 > 详细

学习ASP 文件引用常识

时间:2014-05-17 01:04:00      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:c   ext   http   a   com   文件   

  ASP 文件引用

  Previous Page Next Page #include 命令用于在多重页面上创建需重复使用的函数、页眉、

  页脚或者其他元素等。

  #include 命令

  通过使用 #include 命令,我们可以在服务器执行 ASP 文件之前,把另一个ASP文件插入

  这个文件中。#include 命令用于在多重页面上创建需重复使用的函数、页眉、页脚或者其

  他元素等。

  如何使用 #include 命令

  这里有一个名为 "mypage.asp" 的文件:

  <html>

  <body>

  <h2>Words of Wisdom:</h2>

  <p><!--#include file="wisdom.inc"--></p>

  <h2>The time is:</h2>

  <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>

  <h2>Words of Wisdom:</h2>

  <p>"One should never increase, beyond what is necessary,

  the number of entities required to explain anything."</p>

  <h2>The time is:</h2>

  <p>11:33:42 AM</p>

  </body>

  </html>Including 文件的语法:

  如需在 ASP 中引用文件,请把 #include 命令置于注释标签之中:

  <!--#include virtual="somefilename"-->或者:

  <!--#include file ="somefilename"-->关键词 Virtual

  关键词 virtual 指示路径以虚拟目录开始。

  如果名为 "header.inc" 位于名为 /html 的虚拟目录中,下面这行代码会插入文件

  "header.inc" 中的内容:

  <!-- #include virtual ="/html/header.inc" -->关键词 File

  关键词 File 指示一个相对的路径。相对路径起始于含有引用文件的目录。

  假设文件位于 html 文件夹的子文件夹 headers 中,下面这段代码可引用 "header.inc"

  文件的内容:

  <!-- #include file ="headers\header.inc" -->注意:被引用文件的路径是相对于引用

  文件的。假如包含 #include 声明的文件不在 html 目录中,这个声明就不会起效。

  您同样可以使用关键词 file 和语法 (\) 来引用上级目录中的文件。

  提示和注释

  在上面的一节中,我们使用 ".inc" 来作为被引用文件的后缀。注意:假如用户尝试直接

  浏览 INC 文件,这个文件中内容就会暴露。假如被引用的文件中的内容涉及机密,那么最

  好还是使用 "asp" 作为后缀。ASP 文件中的源代码被编译后是不可见的。被引用的文件也

  可引用其他文件,同时一个 ASP 文件可以对同一个文件引用多次。长春九龙男科医院

  重要事项:在脚本执行前,被引用的文件就会被处理和插入。

  下面的代码无法执行,这是由于 ASP 会在为变量赋值之前执行 #include 命令:

  <%

  fname="header.inc"

  %>

  <!--#include file="<%=fname%>"-->不能在脚本分隔符之间包含文件引用:

  <%

  For i = 1 To n

  <!--#include file="count.inc"-->

  Next

  %>但是这段脚本可以工作:

  <% For i = 1 to n %>

  <!--#include file="count.inc" -->

  <% Next %>

学习ASP 文件引用常识,布布扣,bubuko.com

学习ASP 文件引用常识

标签:c   ext   http   a   com   文件   

原文地址:http://www.cnblogs.com/sxgczs/p/3724944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!