我想用
插入一个文件。但这个文件名不是固定的,
这样写后,iis报错。请问这个问题该如何解决?
---------------------------------------------------------------
that is true, ASP does the include first, then do the scripting, try
1<iframe frameborder="0" src="```
2=ess
3```"></iframe>
or you can always read the file and output there
---------------------------------------------------------------
解析顺序问题!无法解决!重新设计程序!
---------------------------------------------------------------
the answer is no, if you use < !--#include ....-->
but if you use IIS5, you can try to use something like
if condition = true then
Server.Execute "file1.asp"
else
Server.Execute "file2.asp"
end if
or use ScriptControl and evaluate the included file yourself conditionally
---------------------------------------------------------------
同意“ saucer(思归)”的想法;另外,如果真要用你这个方法的话,你可以在“include file="``` =ess
1你试试吧。
2
3Good Luck!
4\---------------------------------------------------------------
5
6include里不能使用变量,所以只好用其它的办法了:
7
8if 条件 then
9<!--#include file="1.asp"-->
10else
11<!--#include file="2.asp"-->
12end if
13
14或者用CASE来加以判断
15\---------------------------------------------------------------
16
17包含文件代码
18<!--#include file=""-->
19始终运行在asp代码的前面,当然就会报错
20\---------------------------------------------------------------
21
22include里不能使用变量,同意 meizz(梅花雨) 的方法
23
24\---------------------------------------------------------------
25
26meizz(梅花雨) 兄
27你的好像也有问题啊!Include不能写到```
28
29```里面的.
if 条件 then
1<!--#include file="1.asp"-->
else
1<!--#include file="2.asp"-->
end if
1
2\---------------------------------------------------------------
3
4补充.
5我到是觉得你应该把变量先写到一个asp文件中.然后在其他文件里面调用他.这样不就好了么?可能语言表达有问题.用的例子说明一下.
6例子:
7inculde.asp
sub info()
判断
end sub
sub theme()
判断
end sub
1
2index.asp
3<#--include file="inculde.asp"-->
代码
call info()
代码判断
if 条件 then
call theme()
else
输出
end if
1就是分别调用.这样应该可以实现你的目的吧!
2\---------------------------------------------------------------
3
4asp中的include跟c中的include差不多,是预先处理的,也就是说,在脚本未得到解释前先处理的,这样你的程序当然得不到执行了,所以产生了找不到包含文件的错误
5
6\---------------------------------------------------------------
7
8我使用过大猫的方法应该可以,而且至少都是在asp3.0的标准
9kingljx
10qq:4863198
11msn:[email protected]
12
13
14\---------------------------------------------------------------
15
16对asp 3.0增加了server.excute的方法,这种方法在以前的版本中是不存在的。
<include file="``` =var
1凡是include语句,都不可以使用asp变量,参见《ASP宝典》。
2
3但你一定要用include,也是有方法的:
4思路:把<include file="```
5=var
6```.asp">整个作为一个字符串变量,然后自己写需要显示的asp程序。
7
8比如需要动态显示、含有include的文件是MyProduct.asp
9那么在转到MyProduct.asp之前,我在另一个文件中写入:
10
11如:
写入文件名变量
FilePath="../viewreports/info"&pid&".htm"
''将文件写入myproduct.asp以供调用
set fs=server.CreateObject("Scripting.FileSystemObject")
AbPath=Server.MapPath("/mysite/viewreports/MyProduct.asp")
set ts=fs.CreateTextFile(AbPath,true)
TxtStr="<html><body><table><!--#include File=""" & FilePath & """ --></table></body></html>"
ts.writeline TxtStr
ts.close
set ts=nothing
set fs=nothing
''将页面转向myproduct.asp
response.redirect "/mysite/viewreports/MyProduct.asp"
end if
1
2
3不知道有没有帮助?</include></include>