首页 | 免费域名 | 个人服务器 | 一流信息监控拦截系统 | 虚拟主机知识库 | ASP 空间 | ASP技术大全 | 下载中心 | 客户服务中心
  7i24 > ASP技术大全 > 技巧与经验 >
    7i24 .Com  
  动态包含文件 (Charles Carroll/蜘蛛精 译)

7i24.Com不停为您服务


包含文件导入页面的过程发生在ASP代码执行前,所以倘你的代码是如下这样:

<%SELECT CASE
  CASE 1 %>
  <!--#include virtual="whatever1.asp"-->
  CASE 2 %>
  <!--#include virtual="whatever2.asp"-->
  CASE 3 %>
  <!--#include virtual="whatever3.asp"-->
<%END SELECT%>

三个包含文件在代码执行前就已导入页面了。

你可以这样:

<%
  whichfile="1"%>
 <!--#include virtual="whatever<%=whichfil%>.asp"-->

这看起来好像有些合理。

<!--#include virtual="whatever.asp"-->

解决的方法是:

<html><head>
<TITLE>includedynamic.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<%
whichfile="bookscifi.asp"
Call ReadDisplayFile(whichfile)
response.write "<hr>"

whichfile="bookhorror.asp"
Call ReadDisplayFile(whichfile)
response.write "<hr>"


whichfile="/learn/test/bookmarketing.asp"
Call ReadDisplayFile(whichfile)
response.write "<hr>"
%>

</body></html>
<%
SUB ReadDisplayFile(FileToRead)
 whichfile=server.mappath(FileToRead)
 Set fs = CreateObject("Scripting.FileSystemObject")
 Set thisfile = fs.OpenTextFile(whichfile, 1, False)
 tempSTR=thisfile.readall
 response.write tempSTR
 thisfile.Close
 set thisfile=nothing
 set fs=nothing
END SUB
%>


所以四海一家的解决之道是:不在包含文件中加入ASP代码,亦即包含文件中不含(<% %> ) 


  2002年1月14日  阅读 1278 次  发送此页给朋友  来源:    版权争议  删除

相关文章:   近期热点:

上一篇: 在特定时间显示特定问候语
下一篇: ADO如何使用Delete语法?
返回上一层...
搜索:

(C)2004-2022 7i24.Com 保留所有权利