📄 asp_incfiles.asp@output=print
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ASP Including Files</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
<h1>ASP Including Files</h1>
<a href="asp_applications.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="asp_globalasa.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">The #include directive is used to create functions, headers, footers,
or elements that will be reused on multiple pages.</p>
<hr />
<h2>The #include Directive</h2>
<p>You can insert the content of one ASP file into another ASP file before the
server executes it, with the #include directive. The #include directive is used to create functions, headers, footers,
or elements that will be reused on multiple pages.</p>
<hr />
<h2>How to Use the #include Directive</h2>
<p>Here is a file called "mypage.asp":</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><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> </pre>
</td>
</tr>
</table>
<p>Here is the "wisdom.inc" file:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre>"One should never increase, beyond what is necessary,
the number of entities required to explain anything."</pre>
</td>
</tr>
</table>
<p>Here is the "time.inc" file:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><%
Response.Write(Time)
%></pre>
</td>
</tr>
</table>
<p>If you look at the source code in a browser, it will look something like this:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><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></pre>
</td>
</tr>
</table>
<br />
<hr />
<h2>Syntax for Including Files</h2>
<p>To include a file in an ASP page, place the #include directive inside comment tags:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><!--#include virtual="somefilename"--></pre>
<pre>or</pre>
<pre><!--#include file ="somefilename"--></pre>
</td>
</tr>
</table>
<h3>The Virtual Keyword</h3>
<p>Use the virtual keyword to indicate a path beginning with a virtual directory.</p>
<p>If a file named "header.inc" resides in a virtual directory named
/html, the following line would insert the contents of "header.inc":</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><!-- #include virtual ="/html/header.inc" --></pre>
</td>
</tr>
</table>
<h3>The File Keyword</h3>
<p>Use the file keyword to indicate a relative path. A relative path begins with the directory that contains the including file.</p>
<p>If you have a file in the html directory, and the file "header.inc" resides in html\headers, the following line would insert
"header.inc" in your file:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><!-- #include file ="headers\header.inc" --></pre>
</td>
</tr>
</table>
<p>Note that the path to the included file (headers\header.inc) is relative to the including file.
If the file containing this #include statement is not in the html directory, the statement will not work.</p>
<hr />
<h2>Tips and Notes</h2>
<p>
In the sections above we have used the file extension ".inc" for included
files. Notice that if a user tries to browse an INC file directly,
its content will be displayed. If your included file contains confidential
information or information you do not want any users to see, it is better to use an
ASP extension. The source code in an ASP file will not be visible after the
interpretation. An included file can also include other files, and one ASP file can include the same file more than
once.
</p>
<p><b>Important:</b> Included files are processed and inserted before the scripts are executed.</p>
<p>The following script will not work because ASP executes the
#include directive before it assigns a value to the variable:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><%
fname="header.inc"
%>
<!--#include file="<%=fname%>"--></pre>
</td>
</tr>
</table>
<p>You cannot open or close a script delimiter in an INC file. This script will not work:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><%
For i = 1 To n
<!--#include file="count.inc"-->
Next
%></pre>
</td>
</tr>
</table>
<p>But this script will work:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><% For i = 1 to n %>
<!--#include file="count.inc" -->
<% Next %></pre>
</td>
</tr>
</table>
<br />
<hr />
<a href="asp_applications.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="asp_globalasa.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -