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="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
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.
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.
上一篇: 随机提取N条记录 推荐
推荐阅读
-
javascript asp教程服务器对象
-
javascript asp教程第十课--global asa
-
javascript asp教程第十三课--include文件
-
javascript asp教程第十一课--Application 对象
-
javascript asp教程第十二课---session对象
-
ASP教程:9、ASP内建对象Application 和 Session
-
ASP javascript Application对象的Contents和StaticObjects做Cache的一些经验
-
php模仿asp Application对象在线人数统计实现方法_PHP教程
-
ASP教程:9、ASP内建对象Application 和 Session
-
php模仿asp Application对象在线人数统计实现方法,application对象_PHP教程