asp中条件式包含某个文件(再次发问)

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

想在asp中条件式包含某个文件      
  ssi的include指令应该是不行的,它是先于其它脚本代码执行的,还有没有其它的方法呢      
  想实现像php里面的:      
  switch($n)   {  
   
          case   "news"                   :       require_once   news_list.php;                       break;  
          case   "articles"           :       require_once   article_type_show.php;       break;  
          case   "classes"             :       require_once   class_type_show.php;           break;  
          case   "download"           :       require_once   down_type_show.php;             break;  
  }    
     
  或者说:      
  if(ture)     {     require_once     news_list.php;     }      
  当某个条件成立时包含某个特定的文件.  
    这样的文件包含效果,asp中可以实现吗?怎么实现呢?    
   
  在前面那贴中nnigou(泥垢)朋友说:    
    那样不可以的      
    可以用     <script     src=     "****.asp     "     >     </script     >方式写在if里面  
  我试了一下,还是不行,好像被包含的文件被asp当成文本输出了,或者说是当成客户端脚本了,知道的朋友烦麻给说说    
 

· 网友精彩回答:

发表者:sluogang

直接在select   case或if之后写要包含的文件就行了。  
  如:  
  文件:a.asp  
  <%response.write("in   a.")%>  
  文件:b.asp  
  <%response.write("in   b.")%>  
  在c.asp中根据条件引用:  
  <%  
  dim   se  
  se=second(now())  
  if   se   mod   2   =1   then  
  %>  
          <%=se%><br>  
          <!--#include   file="a.asp"-->  
  <%else%>  
          <%=se%><br>  
          <!--#include   file="b.asp"-->  
  <%end   if%>  
  就这样了。

发表者:swanzy

在asp3.0中  
   
  if   condition   =   true   then  
  server.execute   "file1.asp"  
  else  
  server.execute   "file2.asp"  
  end   if  
 

发表者:swanzy

function   include(filename)  
  dim   re,content,fso,f,aspstart,aspend  
   
  set   fso=createobject("scripting.filesystemobject")  
  set   f=fso.opentextfile(server.mappath(filename))  
  content=f.readall  
  f.close  
  set   f=nothing  
  set   fso=nothing  
   
  set   re=new   regexp  
  re.pattern="^\s*="  
  aspend=1  
  aspstart=instr(aspend,content,"<%")+2  
  do   while   aspstart>aspend+1    
      response.write   mid(content,aspend,aspstart-aspend-2)  
      aspend=instr(aspstart,content,"%\>")+2  
      execute(re.replace(mid(content,aspstart,aspend-aspstart-2),"response.write   "))  
      aspstart=instr(aspend,content,"<%")+2  
  loop  
  response.write   mid(content,aspend)    
  set   re=nothing  
  end   function  
   
  使用范例:  
   
  include("youinc.asp")  
   
   
  [以上代码摘自互联网,请楼主实验]

.
处理 SSI 文件时出错
© 2006-2008 All Rights Reserved