⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5.htm

📁 IIS5.0超级管理手册-网页开发篇 书籍语言: 简体中文 书籍类型: 网页设计 授权方式: 免费软件 书籍大小: 262 KB
💻 HTM
📖 第 1 页 / 共 5 页
字号:
    <pre style="line-height: 25px">&lt;% Application (&quot;Obj1). MyObjMethod&quot; % &gt;</pre>
    </font>
  </div>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  或者使用本机的一个物件备份:</font></p>
  <div style="line-height: 25px; background-color: #d7d7d7">
    <font face="Arial" size="3" style="line-height: 25px">
    <pre style="line-height: 25px">&lt;%
    Set MyLocalObj1 = Application (&quot;Obj1&quot;) 
    MyLocalObj1.MyObjMethod
%&gt;</pre>
    </font>
  </div>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  另外一种建立全域变数的方法是在Global.asa档案中使用 &lt;OBJECT&gt; 标记来实现。若需更多的资讯,请参阅 
  第7章〈指令档参考〉中的〈Global.asa Reference〉 。</font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">您不能在<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Application&nbsp;</b></font>物件中储存内建物件。例如,下面的每一行都会传回错误讯息:</font></p>
  <div style="line-height: 25px; background-color: #d7d7d7">
    <font face="Arial" size="3" style="line-height: 25px">
    <pre style="line-height: 25px">&lt;%
    Set Application (&quot;Var1&quot;) = Session
    Set Application (&quot;Var2&quot;) = Request
    Set Application (&quot;Var3&quot;) = Response
    Set Application (&quot;Var4&quot;) = Server
    Set Application (&quot;Var5&quot;) = Application
    Set Application (&quot;Var6&quot;) = ObjectContext
%&gt;</pre>
    </font>
  </div>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  您应该对任何全域元件所使用的模型都加以熟悉。用来开发元件的模型对於某个元件例项是否应被指定给某个<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Application&nbsp;</b></font>集合中的一个变数来说有显着的影响。</font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">如果在<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Application&nbsp;</b></font>物件中储存了一个阵列,那麽请您不要直接存取阵列中的元素。例如,下面的指令档就不能执行。</font></p>
  <div style="line-height: 25px; background-color: #d7d7d7">
    <font face="Arial" size="3" style="line-height: 25px">
    <pre style="line-height: 25px">&lt;% Application (&quot;Stored Array&quot;)(3) = &quot;New value&quot; %&gt;</pre>
    </font>
  </div>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  这是因为Application物件被当做一个集合执行,阵列元素StoredArray(3)并没有收到新值。相反地,这个值被包含在Application物件集合中,并且会覆盖在相同阵列元素上的任何资料。</font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  如果在Application物件中储存了一个阵列,那麽最好在检索或改变阵列中的任何一个元素之前备份这个阵列。当使用完这个阵列时,您应该在Application物件中储存它,以便储存您所做的变更。以下指令档可以说明这种情况:</font></p>
  <div style="line-height: 25px; background-color: #d7d7d7">
    <font face="Arial" size="3" style="line-height: 25px">
    <pre style="line-height: 25px">--file1.asp--
&lt;%
   'Creating and initializing the array.
    dim  MyArray ()
    Redim MyArray (5)
    MyArray (0) = &quot;hello&quot;
    MyArray (1) = &quot;some other string&quot;
    
    'Storing the array in the  Application object. 
    Application.Lock 
    Application (&quot;Stored Array&quot;) = MyArray 
    Application.Unlock 
    
    Server.Transfer (&quot;file2.asp&quot;)
%&gt;
   --file2.asp--
&lt;%
   'Retrieving the array from the Application Object
   'and modifying its second element.
   LocalArray = Application (&quot;Stored Array&quot;)
   LocalArray (1) = &quot;there&quot;

   'Printing out the string &quot;ello there.&quot;
   Response.Write ( LocalArray (0)&amp; LocalArray (1))
   
   'Re-storing the array in the Application object.
   'this overwrites the values in StoredArray with the new values.
   Application.Lock
   Application (&quot;Stored Array&quot;) = LocalArray
   Application.Unlock
%&gt;</pre>
    </font>
  </div>
  <p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">范例<br style="line-height: 25px">
 </b></font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  下面的范例利用应用程式变数<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;NumVisits&nbsp;</b></font>来储存某个特定网页被存取的次数。使用<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;lock&nbsp;</b></font>方法是用来确保只有目前的用户端能够存取或改变NumVisits。使用<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Unlock&nbsp;</b></font>方法则是为了让其它的使用者能够存取<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Application&nbsp;</b></font>物件。</font></p>
  <div style="line-height: 25px; background-color: #d7d7d7">
    <font face="Arial" size="3" style="line-height: 25px">
    <pre style="line-height: 25px">&lt;%
   Application.Lock
   Application (&quot;NumVisits&quot;) = Application (&quot;NumVisits&quot;) + 1
   Application.Unlock
%&gt;
   This application page has been visited 
&lt;%= Application (&quot;NumVisits&quot;) %&gt; times!</pre>
    </font>
  </div>
  <p><font face="arial" color="#3e72d7" size="4" style="line-height: 25px">
  <b style="line-height: 25px">Application集合<br style="line-height: 25px">
 </b></font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  <font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">&nbsp;Application&nbsp;</b></font>物件支援下面这些集合:</font></p>
  <font face="arial" color="#000000" size="2" style="line-height: 25px">
  <ul style="line-height: 25px">
    <li style="line-height: 25px">
    <font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
    <b style="line-height: 25px">&nbsp;Contents&nbsp;</b></font><br style="line-height: 25px">
 </li>
    <li style="line-height: 25px">
    <font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
    <b style="line-height: 25px">&nbsp;StaticObjects&nbsp;</b></font><br style="line-height: 25px">
 </li>
  </ul>
  </font>
  <p><font face="arial" color="#3e74d7" size="3" style="line-height: 25px">
  <b style="line-height: 25px">Application Contents集合<br style="line-height: 25px">
 </b></font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  <font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">&nbsp;Contents&nbsp;</b></font>集合包含所有透过某个指令档加到应用程式中的项目。您可以用<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Contents&nbsp;</b></font>集合来得到一个已经被指定为全域应用程式的项目清单。用<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Remove&nbsp;</b></font>和<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;RemoveAll&nbsp;</b></font>方法可以从这个集合中删除这些项目。</font></p>
  <p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">语法<br style="line-height: 25px">
 </b></font></p>
  <div style="line-height: 25px; background-color: #d7d7d7">
    <font face="Arial" size="3" style="line-height: 25px">
    <pre style="line-height: 25px">Application.Contents (Key)</pre>
    </font>
  </div>
  <p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">参数<br style="line-height: 25px">
 </b></font></p>
  <p><font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">&nbsp;Key&nbsp;</b></font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  指定检索的项目名称。</font></p>
  <p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">方法<br style="line-height: 25px">
 </b></font></p>
  <center style="line-height: 25px">
  <table border="1" style="line-height: 25px">
    <tbody style="line-height: 25px">
      <tr style="line-height: 25px">
        <td style="line-height: 25px">
        <font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
        <b style="line-height: 25px">&nbsp;Contents.Remove&nbsp;</b></font></td>
        <td style="line-height: 25px"><font size="2" style="line-height: 25px">
        从集合中删除一个项目。</font></td>
      </tr>
      <tr style="line-height: 25px">
        <td style="line-height: 25px">
        <font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
        <b style="line-height: 25px">&nbsp;Contents.RemoveAll&nbsp;</b></font></td>
        <td style="line-height: 25px"><font size="2" style="line-height: 25px">
        从集合中删除全部项目。</font></td>
      </tr>
  </table>
  </center>
  <p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">注解<br style="line-height: 25px">
 </b></font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  <font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">&nbsp;Application.Content&nbsp;</b></font>s集合包含那些在全域中宣告但没有使用 
  &lt;OBJECT&gt; 标记的项目。它既包括<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Server.CreateObject&nbsp;</b></font>建立的物件,也包括<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Application&nbsp;</b></font>宣告建立的变数。例如,在下面的指令档中,strHello和objCustom都是Application.Contents集合中的元素:</font></p>
  <div style="line-height: 25px; background-color: #d7d7d7">
    <font face="Arial" size="3" style="line-height: 25px">
    <pre style="line-height: 25px">&lt;%
   Application (&quot;strHello&quot;) = &quot;Hello&quot;
   Set Application (&quot;objCustom&quot; = Server.CreateObject (&quot;myComponent&quot;)
% &gt;</pre>
    </font>
  </div>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  Application.Contents集合支援For...Each和For...Next回圈。下面的指令档说明了每一种透过Application.Contents的方法:</font></p>
  <div style="line-height: 25px; background-color: #d7d7d7">
    <font face="Arial" size="3" style="line-height: 25px">
    <pre style="line-height: 25px">&lt;%
   Application (&quot;strText1&quot; = &quot;1234567890&quot; 
   Application (&quot;strText2&quot; = &quot;ABCDEFGHIJ&quot; 
   Application (&quot;strText3&quot; = &quot;A1B2C3D4E5&quot; 
%&gt;
&lt;%
   For Each Key in Application.Contents
     Response.Write Key + &quot;= &quot;+ Application(Key) +&quot;&lt;BR&gt;&quot;
   Next
%&gt;
&lt;%
   For intItem = 1 to Application.Contents.Count
     Response.Write CStr(intItem ) + &quot;=&quot;
     Response.Write Application.Contents(intItem ) + &quot;&lt;BR&gt;&quot;
   Next 
%&gt;</pre>
    </font>
  </div>
  <p><font face="arial" color="#3e74d7" size="3" style="line-height: 25px">
  <b style="line-height: 25px">Application StaticObjects集合<br style="line-height: 25px">
 </b></font></p>
  <p><font face="arial" color="#000000" size="2" style="line-height: 25px">
  <font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
  <b style="line-height: 25px">&nbsp;StaticObjects&nbsp;</b></font>集合包含所有在<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px">&nbsp;Application&nbsp;</b></font>物件领域内使用 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -