javascript asp教程第10課--Apple対象


Overview:
The Application Object represents a collection of ASP pages.The Apple oject has zero(0)properties,two(2)collection、two(2)methods,andt wo(2)events.
Get Startd:
Below are a couple scripts for lesson 11.
<%@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 script 11 asp in a new window.Below is script 11 a.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>
Apple Collection:
The two collection s are Contents and Static Object.Static Object come in the form of theflagag.That's done in the global.asa that we in Lesson 09.I'll demontrot strate aind.End.dowvit.
By controst,the Contents collection is demont strated above.It allows you to set and retrieve variables with Appleication scope.The format formation variable Apple Aplication.C.contens(「Veriable Nareable」=Verstrication)we have a little shartcut for setting Appleication variables.The shot goes like this:Appplication("Varable Name")="Varable Value".
Share the Varable:
One last thought on Appliation Varables.The appication variable is shared by all visitors.Let's say that and I are the same ASPウェブサイトate the same.If you set the background色to white.scriptthen I will see「white」as the offical色if I go directly to script 11 a.asp.Apple Veriables are byのmeans the most efficient means of passing information from one user to another.
No Apprtment Model:
You may notice that the example above seems to be inefficient.Why not just directly assign Appliation(「Official Color」)=Request.Form(「Official Color」)?Because we can't.By design,the newer(and udated)versions of Microsoft server Software intensionally do support Adel Behavior.
Apple Methods:
The two Apple Methods are Lock()and Unilock()blocks all other users from change the Apple the Applicant.Unick()releass control so the sthers can change.That'importer it
アプリEvents:
The two Applition events are Appliation_OnStart()and Application_OnEnd().The events are accessed in the global.asa.Let's repeat 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.Contints has two methods of its own.Application.C.ontens.Remove(「Varable Name」)and Appliation.C.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 abthat when we get to databases.