当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP > ASP Application

ASP
ASP 介绍
ASP Install
ASP 语法
ASP 变量
ASP Procedures
ASP Forms
ASP Cookies
ASP Session
ASP Application
ASP #include
ASP Global.asa
ASP Send e-mail
ASP Response
ASP Request
ASP Application
ASP Session
ASP Server
ASP Error
ASP FileSystem
ASP TextStream

ASP Application


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 901 ::
收藏到网摘: n/a

A group of ASP files that work together to perform some purpose is called an application. The Application object in ASP is used to tie these files together.
我们把通过协同工作来实现一些功能的一组ASP文件称为一个Application。ASP文件中的Application对象是用来把所有的这些文件绑定在一起的。


Application Object
Application 对象

An application on the Web may be a group of ASP files. The ASP files work together to perform some purpose. The Application object in ASP is used to tie these files together.
在网页中的Application可以是一组ASP文件。这些ASP文件在一起协同工作共同实现一些功能。ASP文件中的Application对象是用来把所有的这些文件绑定在一起的。

The Application object is used to store and access variables from any page, just like the Session object. The difference is that ALL users share one Application object, while with Sessions there is one Session object for EACH user.
Application对象是用来存储和访问页面中的变量的(范围是所有页面),这个类似于Session对象的功能。他们的不同点在于Application对象可以被所有的用户访问,而Session对象则只能被单个的用户访问。

The Application object should hold information that will be used by many pages in the application (like database connection information). This means that you can access the information from any page. It also means that you can change the information in one place and the changes will automatically be reflected on all pages.
如果有的信息(一般是通用信息,如:数据库连接信息)是需要被所有的页面访问的,那么,可以使用Application对象。这意味着你可以访问到来自于任何页面的信息;同时,它也意味着:如果你改变了一个地方的信息,那么所有页面中的信息都会随之改变。


 

Store and Retrieve Application Variables
存储及获取Application变量

Application variables can be accessed and changed by any page in the application.
Application可以在任何页面上获取或改变。

You can create Application variables in "Global.asa" like this:
你可以在“Global.asa”文件中建立Application变量,具体如下:

<script language="vbscript" runat="server">

Sub Application_OnStart
application("vartime")=""
application("users")=1
End Sub


</script>

In the example above we have created two Application variables: "vartime" and "users".
在上述的例子当中,我们建立了两个“Application”变量:“Vartime”和“users”

You can access the value of an Application variable like this:
你可以通过以下方法访问Application变量:

There are 
<%
Response.Write(Application("users"))
%>
active connections.

 


Loop Through the Contents Collection
通过循环语句显示“Contents”集合的值

The Contents collection contains all application variables. You can loop through the Contents collection, to see what's stored in it:
“Contents Connection”包含了所有Application变量名称的集合。你可以通过循环语句显示所有存储在“Contents”集合的名称,代码如下:

<%
dim i
For Each i in Application.Contents
Response.Write(i & "<br />")
Next
%>

If you do not know the number of items in the Contents collection, you can use the Count property:
如果你不知道Application变量名的数量,那么你可以用以下的代码获取它:

<%
dim i
dim j
j=Application.Contents.Count
For i=1 to j
Response.Write(Application.Contents(i) & "<br />")
Next
%>

 


Loop Through the StaticObjects Collection
通过循环语句显示所有的“StaticObjects”集合

You can loop through the StaticObjects collection, to see the values of all objects stored in the Application object:
StaticObjects 集合包含 Application 对象范围中用 <OBJECT> 标记创建的所有对象。该集合可用于确定对象特定属性的值,或用于遍历集合并获取所有对象的全部属性。

<%
dim i
For Each i in Application.StaticObjects
Response.Write(i & "<br />")
Next
%>

 


Lock and Unlock
给Application应用程序上锁以及解锁

You can lock an application with the "Lock" method. When an application is locked, the users cannot change the Application variables (other than the one currently accessing it). You can unlock an application with the "Unlock" method. This method removes the lock from the Application variable:
你可以使用“Lock”的方法锁定一个Application。当Application被上锁之后,用户就不能再改变Application变量的值(但用户还可以继续访问其中的数据);你同样也可以通过“Unlock”方法对已上锁的Application进行解锁。具体如下:

<%
Application.Lock
'do some application object operations
Application.Unlock
%>

评论 (0) All

登陆 | 还没注册?