仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 869|回复: 8
打印 上一主题 下一主题

[学习教程] ASP编程:Using the Counters Object (1)

[复制链接]
灵魂腐蚀 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:48:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
无法实现跨操作系统的应用。当然这也是微软的理由之一,只有这样才能发挥ASP最佳的能力。可是我却认为正是Windows限制了ASP,ASP的概念本就是为一个能让系统运行于一个大的多样化环境而设计的;objectIntroduction:
Inyesterdaysarticle,RecordingPageHitswithMicrosoftsPageCounterObjectweexaminedusingMicrosoftsPageCounterobjecttotrackthenumberofhitsforanyparticularWebpage.Unfortunatelythiscomponentisonlybuiltforcountingpageviewhits.Ifwewantedtocountsomethingelse,sayeachtimeauserenteredaparticularsearchqueryintooursitessearchpage,wedbehardpressedwithusingthePageCounterobject.FortunatelyMicrosoftalsoprovidesdeveloperswithamoregenericcountingobject,theCountersobject.Thisobjectcanbeusedtotrackanindeterminentnumberofdeveloper-definedcounters.

BoththePageCounterandCounterscomponentsaremadeavailablewithMicrosoftsIISResourceKit.UnfortunatelythereisshoddydocumentationfortheIISResourceKit-itseemstobeisntalledonIIS5(Windows2000)bydefault,butolderversionsofIISmaynothaveitproperlyinstalled.Refertothepreviousarticle,RecordingPageHitswithMicrosoftsPageCounterObject,formoreinformationontheIISResourceKitandhowtoobtainitifyoudonthaveitinstalled.

AssumingyouhavetheIISResourceKitcomponentsproperlyinstalledyoushouldbeabletocreateaninstanceoftheCountersobjectusingthefollowingcode:

<%Setobj=Server.CreateObject("MSWC.Counters")%>


IfyougetaServer.CreateObjectFailed,Invalidclassstringerrorthenthecomponentsarenotproperlyinstalled.(IfthisisthecaseyoushouldtrychangingMSWC.CounterstoIISSample.Countersandcrossyourfingers.)Ifyoureceivenosucherrormessagethenthecomponentisproperlyinstalled.

UsingtheCountersObject:
TheCountersobjectallowsyoutocreateanynumberofpersistentcounters.WhenusingtheCountersobjectitissmartesttocreateasinlgeapplication-wideinstanceofthisobject.WecanmosteasilydothisbyaddingthefollowinglinetothetopofourGlobal.asafile:

<OBJECTRUNAT=ServerSCOPE=ApplicationID=objCounterPROGID="MSWC.Counters"></OBJECT>


TolearnmoreaboutGlobal.asabesuretoread:EverythingyouWantedtoKnowaboutGlobal.asabutwereafraidtoAskandGlobal.asaEventsaswellastheCreatingaGlobal.asaFilesectionofthesamplechapterofSamsTeachYourselfASP3.0in21Days!

OncethislineisaddedtoGlobal.asayoucanaccesstheCountersobjectfromanyASPpageinyourWebsitebytheobjectsIDthatwespecifiedintheOBJECTtag:objCounter.LikethePageCounterobjectdiscussedinyesterdaysarticle,theCountersobjectisafairlysimpleobjectconsistingofonlyfourmethods:


Get(CounterName)-RetrievesthecurrentvalueofthecounterspecifiedbythenameCounterName

Increment(CounterName)-IncrementsthecurrentvalueofthecounterspecifiedbythenameCounterName

Remove(CounterName)-RemovesthecounterspecifiedbythenameCounterNamefromthetextfilecounters.txt.Thistextfileiswherethecounterinformationispersisted.

Set(CounterName,Value)-SetsthevalueofthecounterspecifiedbythenameCounterNametothevaluespecifiedbyValue
So,oncewehaveaddedtheOBJECTtagabovetoourGlobal.asafilewecanstartworkingwiththeCountersobjectfromanyASPpageonourWebsite.WecouldusetheCountersobjectmuchlikeweusedthePageCounterobject.Forexample,ifwewantedtocreateacountertoseehowmanyfolksvisitedourhomepagewecouldusethefollowingcodeonourhomepage:

<%
Incrementthehomepagecounter
objCounter.Increment("HomePage")

Displayhowmanyhitswevehad
Response.Write"Therehavebeen"&objCounter.Get("HomePage")&"hits."
%>




ThecounternameHomePagedoesntrepresentanyspecialsortofname.Youcansimplycreateacounterbyspecifyingauniquename.Oncethecounteriscreatedyoucanincrementit,changeit,getitscurrentvalue,orremoveitfromanypageonyourWebsite.So,ifonanotherpageyouhadthesamecodeasaboveandtenvisitorshityourhomepageandthenfivevisitorshitthissecondpage,thevaluefortheHomePagecounterwillbe15-10hitsfromthehomepageand5hitsfromthesecondarypage.

InPart2wellexaminetheCountersobjectinmoredetail,lookingathowandwhereitsvaluesarepersisted.Wellalsolookatsomecodetodisplayallofthevaluesofthevariouscounterswemayhavecreated!
</p>asp可以轻松地实现对页面内容的动态控制,根据不同的浏览者,显示不同的页面内容。而浏览者一点觉察不出来,就像为他专门制作的页面一样。使用各种各样的组件,asp可以完成无比强大的功能。
若天明 该用户已被删除
沙发
发表于 2015-1-17 22:54:45 | 只看该作者
另外因为asp需要使用组件,所以了解一点组件的知识(ADODB也是组件)
柔情似水 该用户已被删除
板凳
发表于 2015-1-21 09:49:11 | 只看该作者
我想问如何掌握学习节奏(先学什么再学什么)最好详细点?
飘飘悠悠 该用户已被删除
地板
发表于 2015-1-30 14:08:43 | 只看该作者
虽然ASP也有很多网络教程。但是这些都不系统。都是半路出家,只是从一个例子告诉你怎么用。不会深入讨论,更不会将没有出现在例子里的方法都一一列举出来。
再见西城 该用户已被删除
5#
发表于 2015-2-6 13:11:14 | 只看该作者
以HTML语言整合(HTML负责界面上,ASP则负责功能上)形成一个B/S(浏览器/服务器)模式的网页程序。
山那边是海 该用户已被删除
6#
发表于 2015-3-5 00:11:32 | 只看该作者
完全不知道到底自己学的是什么。最后,除了教程里面说的几个例子,还是什么都不会。
admin 该用户已被删除
7#
发表于 2015-3-11 21:52:35 | 只看该作者
Request:从字面上讲就是“请求”,因此这个是处理客户端提交的东东的,例如Resuest.Form,Request.QueryString,或者干脆Request("变量名")
只想知道 该用户已被删除
8#
发表于 2015-3-19 14:45:45 | 只看该作者
弱类型造成潜在的出错可能:尽管弱数据类型的编程语言使用起来回方便一些,但相对于它所造成的出错几率是远远得不偿失的。
爱飞 该用户已被删除
9#
发表于 2015-3-28 13:18:56 | 只看该作者
从事这个行业,那么你可以学ASP语言,简单快速上手,熟练dreamweav排版,写asp代码,熟练photoshop处理图片,打好基础就行了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-2 03:54

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表