CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  ASP

关于global.asa的一个问题

楼主d4fan(kk)2003-05-01 03:05:08 在 Web 开发 / ASP 提问

这是《asp高级编程》中第三章中的一个例子,目的是显示定义在global.asa中的变量,如果文件夹中有global.asa当然没问题,显示正常,但我把global.asa删除了,显示结果一点变化都没有,按道理说,应该什么变量也显示不出来,不知为什么?  
   
  global.asa如下:  
  <!--   Declare   instance   of   the   ASPCounter   component    
            with   application-level   scope   //-->  
  <OBJECT   ID="ASPCounter"   RUNAT="Server"   SCOPE="Application"    
                  PROGID="MSWC.Counters">  
  </OBJECT>  
   
  <!--   Declare   instance   of   the   ASPContentLink   component    
            with   session-level   scope   //-->  
  <OBJECT   ID="ASPContentLink"   RUNAT="Server"   SCOPE="Session"    
                  PROGID="MSWC.NextLink">  
  </OBJECT>  
   
  <SCRIPT   LANGUAGE="VBScript"   RUNAT="Server">  
   
  Sub   Application_onStart()  
   
    'Create   an   instance   of   an   ADO   Recordset   with   application-level   scope  
      Set   Application("ADOConnection")   _  
            =   Server.CreateObject("ADODB.Connection")  
      Dim   varArray(3)                                                     'Create   a   Variant   array   and   fill   it  
      varArray(0)   =   "This   is   a"  
      varArray(1)   =   "Variant   array"  
      varArray(2)   =   "stored   in   the"  
      varArray(3)   =   "Application   object"                
      Application("Variant_Array")   =   varArray     'Store   it   in   the   Application  
      Application("Start_Time")   =   CStr(Now)         'Store   the   date/time   as   a   string  
      Application("Visit_Count")   =   0                       'Set   counter   variable   to   zero  
   
  End   Sub  
   
  Sub   Application_onEnd()  
      Set   Application("ADOConnection")   =   Nothing  
  End   Sub  
   
  Sub   Session_onStart()  
   
    'Create   an   instance   of   the   AdRotator   component   with   session-level   scope  
      Set   Session("ASPAdRotator")   =   Server.CreateObject("MSWC.AdRotator")  
      Dim   varArray(3)                                                     'Create   a   Variant   array   and   fill   it  
      varArray(0)   =   "This   is   a"  
      varArray(1)   =   "Variant   array"  
      varArray(2)   =   "stored   in   the"  
      varArray(3)   =   "Session   object"  
      Session("Variant_Array")   =   varArray             'Store   it   in   the   Session  
      Session("Start_Time")   =   CStr(Now)                 'Store   the   date/time   as   a   string  
   
    'We   can   access   the   contents   of   the   Request   and   Response   in   a   Session_onStart  
    'event   handler   for   the   page   that   initiated   the   session.   This   is   the   *only*    
    'place   that   the   ASP   page   context   is   available   like   this.  
    'as   an   example,   we   can   get   the   IP   address   of   the   user:    
      Session("Your_IP_Address")   =   Request.ServerVariables("REMOTE_ADDR")  
   
      Application.Lock                                                             'Prevent   concurrent   updates      
      intVisits   =   Application("Visit_Count")   +   1         'Increment   counter   variable  
      Application("Visit_Count")   =   intVisits                 'Store   back   in   Application  
      Application.Unlock                                                         'Release   lock   on   Application  
   
  End   Sub  
   
  Sub   Session_onEnd()  
      Set   Session("ASPAdRotator")   =   Nothing  
  End   Sub  
   
  </SCRIPT>  
   
   
   
   
  show_application.asp如下:  
   
  <%@   LANGUAGE=VBSCRIPT   %>  
  <HTML>  
  <HEAD>  
  <TITLE>The   Application   Object</TITLE>  
  <STYLE   TYPE="text/css">  
  BODY   {font-family:Tahoma,Arial,sans-serif;   font-size:10pt}  
  INPUT   {font-family:Tahoma,Arial,sans-serif;   font-size:9pt}  
  .heading   {font-family:Tahoma,Arial,sans-serif;   font-size:14pt;   font-weight:bold}  
  .subhead   {font-family:Tahoma,Arial,sans-serif;   font-size:12pt;   font-weight:bold;   padding-bottom:5px}  
  .cite   {font-family:Tahoma,Arial,sans-serif;   font-size:8pt}  
  </STYLE>  
  </HEAD>  
  <BODY   BGCOLOR="#FFFFFF">  
  <SPAN   CLASS="heading">The   ASP   Application   Object</SPAN><HR>  
  <!--------------------------------------------------------------------------->  
   
  <%   'look   for   a   command   sent   from   the   FORM   section   buttons  
  If   Len(Request.Form("cmdAdd"))   Then  
        strVarName   =   Request.Form("txtVarName")  
        strVarValue   =   Request.Form("txtVarValue")  
        Application.Lock  
        Application(strVarName)   =   strVarValue  
        Application.Unlock  
  End   If  
  If   Len(Request.Form("cmdRemoveThis"))   Then  
        strToRemove   =   Request.Form("lstRemove")  
        Application.Lock  
        Application.Contents.Remove(strToRemove)  
        Application.Unlock  
  End   If  
  If   Len(Request.Form("cmdRemoveAll"))   Then  
        Application.Lock  
        Application.Contents.RemoveAll  
        Application.Unlock  
  End   If  
  %>  
   
  <P><DIV   CLASS="subhead">The   Application.Contents   Collection</DIV>  
  <%  
  For   Each   objItem   in   Application.Contents  
        If   IsObject(Application.Contents(objItem))   Then  
              Response.Write   "Object   reference:   '"   &   objItem   &   "'<BR>"  
        ElseIf   IsArray(Application.Contents(objItem))   Then  
              Response.Write   "Array:   '"   &   objItem   &   "'   contents   are:<BR>"  
              varArray   =   Application.Contents(objItem)  
              'note:   the   following   only   works   with   a   one-dimensional   array  
              For   intLoop   =   0   To   UBound(varArray)  
                    Response.Write   "&nbsp;   Index("   &   intLoop   &   ")   =   "   &   varArray(intLoop)   &   "<BR>"  
              Next  
        Else  
              Response.Write   "Variable:   '"   &   objItem   &   "'   =   "   _  
                                            &   Application.Contents(objItem)   &   "<BR>"  
        End   If  
  Next  
  %>  
  <P><DIV   CLASS="subhead">The   Application.StaticObjects   Collection</DIV>  
  <%  
  For   Each   objItem   in   Application.StaticObjects  
        If   IsObject(Application.StaticObjects(objItem))   Then  
              Response.Write   "&lt;OBJECT&gt;   element:   ID='"   &   objItem   &   "'<BR>"  
        End   if  
  Next  
  %>  
   
  <!--   collect   values   to   execute   Application   methods   with   -->  
  <FORM   ACTION="<%   =   Request.ServerVariables("SCRIPT_NAME")   %>"   METHOD="POST">  
   
  <P><DIV   CLASS="subhead">Add   a   value   to   the   Application   Object</DIV>  
  <INPUT   TYPE="SUBMIT"   NAME="cmdAdd"   VALUE="&nbsp;&nbsp;&nbsp;">  
  &nbsp;   Application("  
  <INPUT   TYPE="TEXT"   NAME="txtVarName"   SIZE="15"   VALUE="My_New_Value">  
  ")   =   "  
  <INPUT   TYPE="TEXT"   NAME="txtVarValue"   SIZE="20"   VALUE="Testing,   testing   ...">  
  "<P>  
   
  <P><DIV   CLASS="subhead">Remove   a   value   from   the   Application   Object</DIV>  
  <INPUT   TYPE="SUBMIT"   NAME="cmdRemoveThis"   VALUE="&nbsp;&nbsp;&nbsp;">  
  &nbsp;   Application.Contents.Remove("  
  <SELECT   NAME="lstRemove"   SIZE="1">  
  <%  
  For   Each   objItem   in   Application.Contents  
        Response.Write   "<OPTION>"   &   objItem   &   "</OPTION>"  
  Next  
  %>  
  </SELECT>")<BR>  
  <INPUT   TYPE="SUBMIT"   NAME="cmdRemoveAll"   VALUE="&nbsp;&nbsp;&nbsp;">  
  &nbsp;   Application.Contents.RemoveAll  
   
  </FORM>  
   
  <P><DIV   CLASS="subhead">Other   Application   Methods</DIV>  
  Application.Lock<BR>  
  Application.Unlock<P>  
   
  <!--------------------------------------------------------------------------->  
  <HR><SPAN   CLASS="cite">&copy;1999   <A   CLASS="cite"   HREF="http://www.wrox.com/">Wrox   Press</A>   -  
  <A   CLASS="cite"   HREF="http://webdev.wrox.co.uk/default.asp?bookcode=2610">Professional   ASP   3.0</A>   (ISBN:   1-861002-61-0)</SPAN>  
  </BODY>  
  </HTML> 问题点数:0、回复次数:8Top

1 楼saucer(思归)回复于 2003-05-01 06:34:59 得分 0

确认你有相应虚拟目录  
   
  删除后,打开一个DOS窗口,试着重启IIS:  
  iisreset  
   
  然后再访问你的页面,看输出有何不同Top

2 楼siriuscor(siriuscor)回复于 2003-05-01 08:23:58 得分 0

你没有把iis停掉,全局变量当然还在,重启iis就知道了Top

3 楼StudyAll(敢于浮沙筑高台)回复于 2003-05-01 11:05:55 得分 0

完全同意saucer(思归,   MS   .NET   MVP)Top

4 楼d4fan(kk)回复于 2003-05-01 14:06:44 得分 0

我并没有建过虚拟目录。  
   
  重起iis没有用。Top

5 楼lanying(蓝鹰)(问个不休)回复于 2003-05-01 14:22:21 得分 0

你的gloab.asa是放到跟目录虾吗?Top

6 楼d4fan(kk)回复于 2003-05-01 18:54:11 得分 0

目录结构为:  
  根目录:文件Default.asp、gloab.asa,和文件夹session、application  
  文件夹session:Default.asp、show_session.asp、abandon.asp  
  文件夹application:Default.asp、show_application.aspTop

7 楼wuhuxia(古仔)回复于 2003-05-01 19:10:41 得分 0

不管怎么样你肯定有个执行这些文件的站点或是某个站点下面的虚拟目录存在阿  
   
  否则你靠什么来执行这些asp文件?Top

8 楼d4fan(kk)回复于 2003-05-01 21:50:39 得分 0

是有个执行这些文件的站点,但没建过虚拟目录。Top

相关问题

  • 求教一个global。asa得问题
  • 关于ASA Database
  • ASA是什么?
  • ASA ASE DB2何意?
  • ASA 高手请进!
  • asa 和 interbase比哪个好?
  • ASA下载完成,多谢
  • ASA数据库问题
  • 如何装上asa驱动!?
  • asa数据库的难题?

关键词

  • application
  • asp
  • objitem
  • vararray
  • intloop
  • contents
  • collection
  • response
  • array
  • write

得分解答快速导航

  • 帖主:d4fan

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo