ASP忽略包含文件不存在的错误信息提示

来源:百度知道 编辑:UC知道 时间:2024/06/06 07:50:14
<%set fso=Server.CreateObject("Scripting.FileSystemObject")
head=server.MapPath ("head.htm")
if fso.FileExists(head) then%>
<!--#include file="head.htm"-->
<%else%>
<!--#include file="head2.htm"-->
<%end if%>

请教:以上代码执行后,如果head.htm不存在会出错误信息。如何屏蔽?

不能这么写,“<!--#include……”在开始运行ASP之前已经加载了!
如果include的东西是要执行的建议写成Function的形式预先加载,在条件判断中区别加以调用……
如果include的东西不是执行的,直接response.write出来给浏览器就可以了……注:用客户端代码的方式引用也是不错的选择……

<%On Error resume Next
set fso=Server.CreateObject("Scripting.FileSystemObject")
head=server.MapPath ("head.htm")
if fso.FileExists(head) then%>
<!--#include file="head.htm"-->
<%else%>
<!--#include file="head2.htm"-->
<%end if%>

ASP是不能动态包含的

如果包含的页面是静态的,可以用fso读取再用Response.Write输出

干脆来一个try catch,帮助报错,如果报错在 catch里面返回一个 a=true条件,下面再以a为条件判断

肯定会报错,而且没法屏蔽,是系统级的