javascript asp教程第十一课--Application 对象_ASP基础

Overview:

The Application Object represents a collection of ASP pages. The Application object has zero (0) properties, two (2) collections, two (2) methods, and two (2) events.

Get Started:

Below are a couple scripts for lesson11.

<%@LANGUAGE="JavaScript"%>
<%
//No ASP Here, just a regular HTML Page
%>
<HTML>
<FORM ACTION="script11a.asp" METHOD="Post">
<STRONG>Would you like to chose the official Application color?</STRONG><BR>
<SELECT NAME="OfficialColor">
<OPTION>red</OPTION>
<OPTION>white</OPTION>
<OPTION>blue</OPTION>
</SELECT><BR>
<INPUT TYPE="Submit" VALUE="Yes, click here">
</FORM>
No, <A HREF="script11a.asp">click here</A>.
</HTML>

Click Here to run script11.asp in a new window. Below is script11a.asp.

<%@LANGUAGE="JavaScript"%>
<HTML>
<%
Application.Lock()
var OfficialColor = new String( Request.Form("OfficialColor") )
if (OfficialColor=="red")
	{
	Application("OfficialColor") = "red"
	}
if (OfficialColor=="white")
	{
	Application("OfficialColor") = "white"
	}
if (OfficialColor=="blue")
	{
	Application("OfficialColor") = "blue"
	}
if (OfficialColor=="undefined")
	{
	//Do nothing. Just leave the color alone.
	}
Application.Unlock()
%>
<BODY BGCOLOR="<%=Application("OfficialColor")%>">
<STRONG>
The official application color is <%=Application("OfficialColor")%>.<BR>
</STRONG>
</BODY>
</HTML>

Application Collections:

The two collections are Contents and StaticObjects. StaticObjects come in the form of the <OBJECT> flag. That's done in the global.asa that we saw in Lesson 09. I'll demonstrate it again down below.

By contrast, the Contents collection is demonstrated above. It allows you to set and retrieve variables with Application scope. The format for setting an Application variable is Application.Contents("VariableName")="VariableValue". However, since Contents is the default Collection, we have a little shortcut for setting Application variables. The shortcut goes like this: Application("VariableName")="VariableValue".

Share the Variable:

One last thought on Application Variables. The application variable is shared by all visitors. Let's say that you and I are on the same ASP web site at the same time. If you set the background color to white in script11.asp, then I will see "white" as the official color if I go directly to script11a.asp. Application Variables are by no means the most efficient means of passing information from one user to another.

No Apartment Model:

You may notice that the example above seems to be inefficient. Why not just directly assign Application("OfficialColor") = Request.Form("OfficialColor")? Because we can't. By design, the newer (and updated) versions of Microsoft server software intentionally do not support Apartment Model Behavior.

Application Methods:

The two Application Methods are Lock() and Unlock(). Lock() blocks all other users from changing the Application variables. Unlock() releases control so that other users can change it. That's important on a larger site where multiple users may be trying to access the same page at the same time.

Application Events:

The two Application events are Application_OnStart() and Application_OnEnd(). These events are accessed in the global.asa. Let's repeat that script from lesson 09.

<OBJECT RUNAT=Server SCOPE=Session ID=MyInfo PROGID="MSWC.MyInfo">
</OBJECT>

<SCRIPT RUNAT="Server" LANGUAGE="JavaScript">
function Application_OnStart()
	{
	Application("someVariableName")="some value"
	}
function Application_OnEnd()
	{
	Application.Contents.RemoveAll()
	}
function Session_OnStart()
	{
	Session.Timeout=15
	}
function Session_OnEnd()
	{
	//Do Nothing
	}
</SCRIPT>

<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll"
-->

Misc. Items:

Application.Contents has two methods of its own. Application.Contents.Remove("VariableName") and Application.Contents.RemoveAll().

You'll notice there are also Session Events in the global.asa. We'll deal with those in Lesson 12. You'll also notice a call to the ADO Library. We'll talk about that when we get to databases.

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索javascript
对象
获取application对象、jsp application对象、application对象、java application对象、js application对象,以便于您获取更多的相关知识。

时间: 2024-09-19 09:07:04

javascript asp教程第十一课--Application 对象_ASP基础的相关文章

javascript asp教程第十一课--Application 对象

Overview: The Application Object represents a collection of ASP pages. The Application object has zero (0) properties, two (2) collections, two (2) methods, and two (2) events. Get Started: Below are a couple scripts for lesson11. <%@LANGUAGE="Jav

javascript asp教程第八课--request对象_ASP基础

Request Object: Request has five (5) Collections, one (1) Property, and one (1) Method. You'll use the Collections far more than the property or the method. Request Collections: Below is a table of the Request Collections and descriptions of how they

javascript asp教程第六课-- response方法_ASP基础

response 对象:reponse是asp中六个对象之一.它代表了服务器端对浏览器的回应.response有8种方法,9种属性和一个集.在这一课,我们就重点讲述方法.方法:在javascript中,asp方法使用括号.请注意依赖response.buffer的两个方法,我们将在下一课讲到他们.同样应该注意到addheader()和redirect(),因为他们必须优先于write()执行.所有的方法都在上面描述和演示了.下面我将详细讲述每一个方法.我将花点额外的时间来讲述我们用的最多的两个方

javascript asp教程第七课--response属性_ASP基础

Below is a table of Response Properties along with examples and explanations. Response Properties Buffer Response.Buffer = trueAllows for the buffering of outputCacheControl Response.CacheControl="Public" Sets Cache to "Public" or &quo

javascript asp教程第八课--request对象

Request Object: Request has five (5) Collections, one (1) Property, and one (1) Method. You'll use the Collections far more than the property or the method. Request Collections: Below is a table of the Request Collections and descriptions of how they

javascript asp教程第十二课---session对象_ASP基础

Overview: The Session Object is how you track a single user across many pages. It has four (4) properties, two (2) collections, one (1) method, and two (2) events. Get Started: In this series of examples we will create a password system. We will use

javascript asp教程第六课-- response方法

response 对象: reponse是asp中六个对象之一.它代表了服务器端对浏览器的回应.response有8种方法,9种属性和一个集.在这一课,我们就重点讲述方法. 方法: 在javascript中,asp方法使用括号.请注意依赖response.buffer的两个方法,我们将在下一课讲到他们.同样应该注意到addheader()和redirect(),因为他们必须优先于write()执行. 所有的方法都在上面描述和演示了.下面我将详细讲述每一个方法.我将花点额外的时间来讲述我们用的最多

javascript asp教程第三课 new String() 构造器

开始: new String() 是本课程计划中较早出现的另一个让人感觉到奇怪的地方.但和转义字符一样, new String()是创建一个成功的asp javascript应用的必须元素.下面是本课的两个脚本: 下面是实际上承担重量的脚本: 行为中的new String( ): 现在我们来看看下面的asp行. Request.Form 我们将在后面有独立的课程来讲授.下面才是我们现在要讲的重点.在request.form中所持有的数据(来自用户的数据)并不是一个javascript数据类型.相

javascript asp教程第五课--合二为一_ASP基础

两条防线,一个函数: 试问你如何能保证客户端和服务器端具有相同的功能?表单域的验证闪现在我们眼前.别人把你的html复制到另外一个脚本,然后改变客户端的表单域验证--这并不是一件难事.摆在眼前的解决方法是将表单域的验证放置在服务器端.但那又意味着因为使用者的一个小错误,都要给服务器端要返回一串的错误信息.那么,我们何不同时拥有二者呢?不仅仅如此,我们还可以在客户端和服务器端使用同一个javascript函数来保证二者的完全一致性. 看看下面这一小段,请特别注意一下checkMyZip()函数.