|
|
|
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代码,亦即包含文件中不含(<% %> )
|
|
|