北京网站建设|北京网站开发|北京网站改版|北京网页设计|北京网站建设公司 北京网站建设|北京网站开发|北京网站改版|北京网页设计|北京网站建设公司
新闻资讯
北京网站建设→快速开发通道
2007-8-3 21:52:42
动态包含文件 (Charles Carroll/蜘蛛精 译)

包含文件导入页面的过程发生在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
TITLEincludedynamic.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
%

北京网站建设→服务热线:010-58631674/1694
北京网站建设|北京网站开发|北京网站改版|北京网页设计|北京网站建设公司