|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
强大的可扩展性。ASP具有强大的扩展性,可以实现与多种网络、硬件设备的连接:通过专用的通讯线路远程接入企业;通过远程拨号服务器为远程拨号客户提供服务;通过WAP为移动电话互联网客户服务。SurveyDescr.asp
<!--#includefile="include/Startup.asp"-->
<!--#includefile="utils/Survey.asp"-->
<%
//============================================
//NOTE:allsourcecodedownloadedfromCoverYourASPwaswrittenby
//JamesShaw(unlessstatedotherwise),andiscopyright(c)2000by
//JamesShaw.Youmayusethissourcecodeonyourwebsites,but
//pleasedontpublishordistributeinanyway.
//
//IwouldappreciateanHTMLcommentinanycodeyouuse,i.e.
//<!--portions(c)james@CoverYourASP.com-->
//(seeFooter(),documentedinSSI.aspfordetailsonhowtodothis)
//
//<shamelessplug>
//PleasecontactmetodiscussanyASPcontractworkyoumayhave.
//</shamelessplug>
//============================================
//outputrelevantmetatags
Init("Surveyyourreaders");
//outputcommontopofpage
Header(Surveyyourreaders);
//outputpagecontent
Content();
//outputcommonbottomofpage
Footer();
//============================================
//thecontentofthispage-everypagehasafunctionContentthat
//iscalledabove.
//============================================
functionContent()
{
Out(<tdcolspan=2width="80%"valign="top">);
//ifthesurveyhasntbeensubmittedyet...
if(!Request.Form.Count)
{
//...displaysomeblah,blah
Out(Finally,surveyscometoCoverYourASP!Ivebeenwantingtoaskyouguysandgals
questionsforalongtime,andnowIcan.Itsuptoyouifyouwanttoanswerofcourse!);
Out(<p>Ofcourse,therealbenefittoyouisthatifyoutellmewhatyoulikeIllprobably
provideit.Ifyousendinyour<ahref="Donate.asp">donations</a>theprobabilityincreasesrather
dramatically!);
Out(<p>Taketheexamplesurveybelowifyouhavethetimeandinclination.Iplantopostmore
inaspecialsurveycategory,andstartofferingincentivestotakethem.);
Out(<p>Afterwards,lookatthecode.Ithinkyoullbesurprisedhowsimpleitistocreate
surveyswiththiscode.Thispagehasonefunctioncallinit,withjustoneparameter-thenameofthe
survey!Allquestions,answersandresultsarestoredinthedatabase.);
}
//showthesurvey,orprocessitsinput
ProcessSurvey(Whoareyouandwhatdoyouthink?);
if(!Request.Form.Count)
Out(<p><ahref="ShowSource.asp?page=SurveyDescr"></a></center>);
Out(</td>);
Out(<tdwidth="20%"valign="top">);
//showrotatingbanners
ShowBanners(4);
Out(</td>);
}
%>
utils/Survey.asp
<%
//============================================
//NOTE:allsourcecodedownloadedfromCoverYourASPwaswrittenby
//JamesShaw(unlessstatedotherwise),andiscopyright(c)2000by
//JamesShaw.Youmayusethissourcecodeonyourwebsites,but
//pleasedontpublishordistributeinanyway.
//
//IwouldappreciateanHTMLcommentinanycodeyouuse,i.e.
//<!--portions(c)james@CoverYourASP.com-->
//(seeFooter(),documentedinSSI.aspfordetailsonhowtodothis)
//
//<shamelessplug>
//PleasecontactmetodiscussanyASPcontractworkyoumayhave.
//</shamelessplug>
//============================================
//============================================
//displayorprocessthenamedsurvey
//============================================
functionProcessSurvey(sName)
{
//hasthesurveyformbeensubmitted?
if(Request.Form.Count)
{
//connecttothedatabase
DBInitConnection();
varsSurvey=""+Request.Form("Survey");
//onlyupdatethesurveywhennocookie
if(""==Request.Cookies(sSurvey))
{
//getthedatafromtheformandupdatethedatabase
//useanenumeratortogetnameandvalue
vare=newEnumerator(Request.Form);
while(!e.atEnd())
{
varoItem=e.item();
//incrementthecurrentnumberoftimesthisanswerhasbeenchosen
oConnection.Execute(UPDATESurveyAnswersSETHits=Hits+1WHEREQuestion="+oItem+"AND
Answer="+Request.Form(oItem)+";);
e.moveNext();
}
//notethatsettingcookiehereassumeswearebuffering
//theReponse.Writes-cookiesmustbesetbeforeany
//HTMLissenttotheclient
Response.Cookies(sSurvey)="1";
//Imnotsettingtheexpiresonthecookie,soitllgo
//awaywhenthebrowserisclosed.Ijustwantedtostop
//thesurveyincrementingifthepagerefreshed.
}
//nowdisplayalltheanswerstothesurvey
Out(<p>Thanksfortakingpartinour"+sSurvey+"survey!Theanswersthateveryonehas
givensofarareshownbelow:);
//thelastquestionwedisplayed
varsLast="";
//getalltheselectedanswers,sortedbyquestionandhits
DBGetRecords(SELECTSurveyAnswers.Question,Answer,HitsFROMSurveyAnswersINNERJOIN
SurveyQuestionsONSurveyQuestions.Question=SurveyAnswers.QuestionWHERESurvey="+sSurvey+"AND
Hits>0ORDERBYSurveyAnswers.Question,HitsDESC;);
varfScale;
while(!oRecordSet.EOF)
{
//displayquestionwhenitchanges
varsIntQuestion=""+oRecordSet(0);
//sliceoffcharsusedforsorting
varsQuestion=sIntQuestion.slice(2);
//getanswer
varsIntAnswer=""+oRecordSet(1);
//sliceoffcharsusedforsorting
varsAnswer=ExpandMacros(sIntAnswer.slice(2));
varnReaders=oRecordSet(2)-0;
if(sQuestion!=sLast)
{
Out(<h5>+sQuestion+</h5>);
sLast=sQuestion;
Out(<fontcolor="red">"+sAnswer+"wasthetopanswer(+nReaders+readers)
</font><br>);
fScale=300.0/nReaders;
}
else
{
Out("+sAnswer+"waschosenby+nReaders+readers<br>);
}
Out(<imgsrc="http://edu.cnzz.cn/NewsInfo/images/Dot.gif"height="8"width="+(nReaders*fScale)+"><br>);
oRecordSet.MoveNext();
}
//releasetheconnectionASAP
DBReleaseConnection();
}
else
{
//someinitialinstructions
Out(<p>Therearen anyimportantinstructionswhenansweringthesequestions-exceptyou
don havetoanswerany.Allareoptional-ifyoudon likeaquestion,ornoneoftheanswersare
relevant,justmoveontothenextone!);
//connecttothedatabase
DBInitConnection();
//getthequestionsfromthedatabase
DBGetRecords(SELECTQuestionFROMSurveyQuestionsWHERESurvey="+sName+"ORDERBY
Question;);
if(oRecordSet.EOF)
{
Out(Noquestionswerefoundforsurvey"+sName+"<p>);
return;
}
//storethequestionsinanarray
varsIntQuestions=newArray;
varnQuestions=0;
while(!oRecordSet.EOF)
{
sIntQuestions[nQuestions++]=""+oRecordSet(0);
oRecordSet.MoveNext();
}
Out(<formaction="+Request.ServerVariables(SCRIPT_NAME)+"method="post">);
//somehiddenfieldstopassdatathroughtoresultspage
Out(<inputtype="hidden"name="Survey"value="+sName+">);
//nowloopthroughthequestions
for(varnQuestion=0;nQuestion<nQuestions;nQuestion++)
{
varsIntQuestion=sIntQuestions[nQuestion];
//sliceoffcharsusedforsorting
varsQuestion=sIntQuestion.slice(2);
//gettheanswersfromthedatabase
DBGetRecords(SELECTAnswer,AnswerTypeFROMSurveyAnswersWHEREQuestion="+sIntQuestion+"
ORDERBYAnswer;);
Out(<h5>+sQuestion+</h5>);
while(!oRecordSet.EOF)
{
//gettheanswer
varsIntAnswer=""+oRecordSet(0);
//sliceoffcharsusedforsorting
varsAnswer=ExpandMacros(sIntAnswer.slice(2));
varsAnswerType=""+oRecordSet(1);
switch(sAnswerType)
{
caseradio:
Out(<inputtype="radio"name="+sIntQuestion+"value="+sIntAnswer+">+
sAnswer);
break;
default:
break;
}
Out(<br>);
//getnextanswer
oRecordSet.MoveNext();
}
}
Out(<p><inputtype="submit"value="Submitanswers">);
Out(</form>);
//releasetheconnectionASAP
DBReleaseConnection();
}
}
//============================================
//addlinkstotextwhere*?macrosarefound,e.g.*dexpandsto
//<ahref="Donate.asp">Sendadonation!</a>
//NOTE:currentlyassumesexpansionsarealwaysatendofline
//============================================
functionExpandMacros(sText)
{
varsMacros=newArray(
**,
*d
);
varsExpansions=newArray(
<ahref="Contact.asp"target="CYAEXternal">Youneedtosendmefeedback!</a>,
<ahref="Donate.asp"target="CYAEXternal">sendadonation!</a>
);
for(vari=0;i<sMacros.length;i++)
{
varnPos=sText.indexOf(sMacros[i]);
if(-1!=nPos)
{
sText=sText.slice(0,nPos)+sExpansions[i];
break;
}
}
returnsText;
}
%>
utils/Database.asp
<%
//============================================
//NOTE:allsourcecodedownloadedfromCoverYourASPwaswrittenby
//JamesShaw(unlessstatedotherwise),andiscopyright(c)2000by
//JamesShaw.Youmayusethissourcecodeonyourwebsites,but
//pleasedontpublishordistributeinanyway.
//
//IwouldappreciateanHTMLcommentinanycodeyouuse,i.e.
//<!--portions(c)james@CoverYourASP.com-->
//(seeFooter(),documentedinSSI.aspfordetailsonhowtodothis)
//
//<shamelessplug>
//PleasecontactmetodiscussanyASPcontractworkyoumayhave.
//</shamelessplug>
//============================================
//globals
varoConnection;
varoRecordSet;
//enums
//Connection.StateandRecordset.Stateproperty
varadStateClosed=0;//theobjectisclosed.
varadStateOpen=1;//theobjectisopen.
varadStateConnecting=2;//theobjectisconnecting.
varadStateExecuting=4;//theobjectisexecutingacommand.
varadStateFetching=8;//therowsoftheobjectarebeingfetched.
//Recordset.Cursorproperty
varadOpenUnspecified=-1;//doesnotspecifythetypeofcursor.
varadOpenForwardOnly=0;//(default)aforward-onlycursor,i.e.yougetonlyonepassthruthedata!
varadOpenKeyset=1;//cangoinanydirection,andasabonusyoullseechangesotherusers
make.EXPENSIVE!
varadOpenDynamic=2;//asKeyset,butalsoyoucanseeadditions/deletionsotherusersmake.
EXPENSIVE!
varadOpenStatic=3;//cangoinanydirection,butread-only.
//Recordset.LockTypeproperty
varadLockUnspecified=-1;//doesnotspecifyatypeoflock.
varadLockReadOnly=1;//(default)guess!
varadLockPessimistic=2;//guaranteedtowork
varadLockOptimistic=3;//recordslockedonlywhenyoucallUpdate.fingerscrossed
varadLockBatchOptimistic=4;//requiredforbatchupdatemode
//============================================
//exampleusage:
//DBInitConnection();
//
//DBGetRecords("SELECT*FROMSomewhere");
//
//...useoRecordSet
//
//DBReleaseRecords();//optionalstep
//
//DBGetRecords("SELECT*FROMSomewhereElse");
//
//...useoRecordSet
//
//DBReleaseRecords();//optionalstep
//
//DBReleaseConnection();
//============================================
//============================================
//initializesdatabasevariablesforfirstuseonpage-leaveittothe
//lastpossiblesecondbeforecallingthisfunction
//============================================
functionDBInitConnection()
{
//dontopenitagainifalreadyopened!
if(oConnection!=undefined)
return;
//youcanopenRecordsetobjectswithoutaConnectionobject,but
//itsfarlessefficientifyouareopeningmultipleRecordsets.
//
//ifyoudontcreateaConnectionobjectADOcreatesanewonefor
//eachnewRecordset.Open,evenifyouusethesameconnectionstring.
oConnection=Server.CreateObject(ADODB.Connection);
//openthedatabase-useMapPathtomakerelativepathintophysicalpath
//NOTE:keepyourdatabasepathasecret-nastypeopleareeverywhere!
//2.changethe4.0to3.51whenusingAccess97
oConnection.Open(Provider=Microsoft.Jet.+sDBDriver+;DataSource=+Server.MapPath(
sDBPath));
//createaRecordset
oRecordSet=Server.CreateObject(ADODB.Recordset);
}
//============================================
//tidiesupafterDBInitConnection
//============================================
functionDBReleaseConnection()
{
//dontreleasetheconnectionifnotconnected!
if(oConnection==undefined)
return;
//closeanddeletetheRecordsetobject
DBReleaseRecords();
oRecordSet=undefined;
//DontcallCloseiftheRecordsetfailedtoOpenproperly,i.e.its
//StateisstilladStateClosed(0)
if(oConnection.State!=adStateClosed)
oConnection.Close();
oConnection=undefined;
}
//============================================
//executesthepassedinSQLstatementandreturnsaread-only
//forward-onlyoRecordSetobject
//============================================
functionDBGetRecords(sSQL)
{
//iftheRecordsetisalreadyopen,closeit
DBReleaseRecords();
//wecoulduseoRecordSet=oConnection.Execute(sSQL)here
//butthenwewillalwaysgetbackaread-only,forward-onlycursor.
//(admittedlythisisthemostusedtype,butstill)
//useoRecordSet.Openandwehavefarmorecontrol.Fordetails
//readthedefinitionsoftheenumsatthetopofthisfile.
//rememberthatthiscanfailifpassedgarbage,andhencethe
//Recordsetwillremainclosed,State==adStateClosed
oRecordSet.Open(sSQL,oConnection,adOpenForwardOnly,adLockReadOnly);
}
//============================================
//tidiesupafterDBGetRecords
//============================================
functionDBReleaseRecords()
{
//whenyouhavefinishedwithanopenRecordsetobject,callthe
//Closemethodtoreleaseitsresources.YoucancallOpenagain.
//DontcallCloseiftheRecordsetfailedtoOpenproperly,i.e.its
//StateisstilladStateClosed
if(oRecordSet!=undefined&&oRecordSet.State!=adStateClosed)
oRecordSet.Close();
}
%>
对于中小型web应用来说,php有很强的竞争力,linux+apache+mysql+php(lamp)的组合几乎可以胜任绝大多数网站的解决方案,对于大型应用来讲,对于系统架构要求更高,需要有成熟的框架支持,jsp的struts是个不错的框架,国内介绍它的资料也非常多,应用逐渐广泛起来。asp就不用说了, |
|