1、前言
因为目前的开发工作碰到了一个模块,里面大量使用了.inc类型的文件。asp页面全是由.inc组合起来的,包括asp页面里面引用的一些vbscript参数也全是来自于引入的.inc里面的。因为之前没见过这种写法,所以花费了大量的时间和精力去理清这些.asp和.inc不同页面之间组合调用复用的关系。正好目前开发完了手头有空,就稍微了解并整理了一下.inc文件相关的知识。
2、介绍
其实.inc后缀,我查了网上的资料以及结合自己实际开发中的体验。.inc不能确切的称之为一种特定的文件类型。inc的意思是“include”。就是一种专门嵌套在其他文件中的文件。实际上后缀名对文件包含是无所谓的,你也可以不叫.inc,可以叫.txt .asp .html。通过<include />引入都可以嵌套在别的页面中使用。
3、使用
PrepareData.inc
<%
'用于提供数据
dim arrInfo(3,3)
function PrepareDataX()
arrInfo(0,0)="小学"
arrInfo(0,1)="001"
arrInfo(0,2)="张三"
arrInfo(1,0)="中学"
arrInfo(1,1)="002"
arrInfo(1,2)="李四"
arrInfo(2,0)="大学"
arrInfo(2,1)="003"
arrInfo(2,2)="王五"
end function
%>
TableTh.inc
<!-- #INCLUDE VIRTUAL="/root/inc/PrepareData.inc" -->
<%
'用于提供页面样式
function MyTable()
Call PrepareDataX()
%>
<table border=1>
<tr>
<th>学校</th>
<th>班级</th>
<th>姓名</th>
</tr>
<tr>
<td><%=arrInfo(0,0)%></td>
<td><%=arrInfo(0,1)%></td>
<td><%=arrInfo(0,2)%></td>
</tr>
<tr>
<td><%=arrInfo(1,0)%></td>
<td><%=arrInfo(1,1)%></td>
<td><%=arrInfo(1,2)%></td>
</tr>
<tr>
<td><%=arrInfo(2,0)%></td>
<td><%=arrInfo(2,1)%></td>
<td><%=arrInfo(2,2)%></td>
</tr>
</table>
<%
end function
%>
HelloWorld.asp
<!-- #INCLUDE VIRTUAL="/root/inc/TableTh.inc" -->
<%
'组合一下
'直接调用TableTh.inc里面写好的并且有数据的页面样式
Call MyTable()
%>
效果:
4、总结
.inc文件是通过 <!-- #INCLUDE VIRTUAL="/root/inc/TableTh.inc" --> 这样的方式引入了,第一眼看上去感觉有点类似于C语言的 #include "stdio.h"。不过确实这种由许多.inc组合起来的看起来真的很烦。
注:我的代码是跑在IIS服务器上的,关于IIS服务器可以参考我之前的这篇:使用IIS服务器搭建一个网站_iis搭建网站_金斗潼关的博客-CSDN博客