ASP网页设计创立一个Web投票体系
我想详细了解ASP整站代码与PSP整站代码有什么优缺点,那个更好,更安全,更用容易维护,和管理。。。web|创立|投票上面zip文件:http://www.content.aspdir.co.uk/files/Article-11.zipDuringthisarticleyouwilllearnhowtoconstructyourownwebpollusingASP.Thearticlepresumesyou
alreadyunderstandbasicdatabaseinteraction.
Thefollowingsamplesofcodeallowausertoselectoneoffouroptionstoaquestion.Theusersvoteis
thenrecordedinadatabaseandtheuseristakentoapagewheretheresultsforeachoptioncanbe
viewedinstatistical,numericalandgraphicalform.Notbad,huh?
Thewholeapplicationisbasedonthedatabaseitself,sowhenthevalueswithinthedatabasearealtered,
theapplicationautomaticallychanges.Thedatabasedesignitself,isnotincludedwithinthisarticleso
makesuretodownloadacopyoftheentireapplication,includingthedatabasebeforerunningthecode.
Thecodeforthefirstpageisshownasfollows:-
Page:default.asp
<%
Connectstodatabaseusingrecordsetmethod
FunctiondataConn(database,connection,recordset)
Setconnection=Server.CreateObject("ADODB.Connection")
Setrecordset=Server.CreateObject("ADODB.Recordset")
connection.Open"DBQ="&Server.Mappath(database)&";Driver={MicrosoftAccessDriver(*.mdb)};"
EndFunction
%>
<HTML>
<HEAD>
<TITLE>PollExample</TITLE>
</HEAD>
<BODY>
<FORMname="languages"method=postaction="pollResults.asp">
<P>Whatisyourfavoutritelanguage?</P>
<%
CallsdataConnfunctiontoopendbPoll.mdb
dataConn"files/dbPoll.mdb",POdc,LArs
SelectsallfieldswithintblLanguages
LArs.Open"SELECT*FROMtblLanguages",POdc
Loopthroughanddisplayeachrecordwithinthedatabaseasaradiobutton
DoWhileNotLArs.EOF
Response.WriteLArs("Language")&":<INPUTtype=radioname=languagevalue="&LArs("Language")
&"><BR>"
LArs.MoveNext
Loop
Closedatabaseconnection
LArs.Close
POdc.Close
SetPOdc=Nothing
%>
<Ahref="pollResults.asp">ViewPoll</A>
<INPUTtype=submitvalue="Vote">
</FORM>
</BODY>
</HTML>
Onceconnectedtothedatabasethescriptloopsthrougheachrecord,anddisplaysthatoptionasaradio
button.WhentheVotebuttonispressed,theindividualvalueoftheselectedradiobuttonissubmitted
tothenextpage.
Thecodeforthenextpageisshownbelow:-
Page:pollResults.asp
<%
Defineallvariablesthatwillbeused
DimI,Percent
Connectstodatabaseusingrecordsetmethod
FunctiondataConn(database,connection,recordset)
Setconnection=Server.CreateObject("ADODB.Connection")
Setrecordset=Server.CreateObject("ADODB.Recordset")
connection.Open"DBQ="&Server.Mappath(database)&";Driver={MicrosoftAccessDriver(*.mdb)};"
EndFunction
%>
<HTML>
<HEAD>
<TITLE>PollingSample</TITLE>
</HEAD>
<BODY>
<%
CallsdataConnfunctiontoopendbPoll.mdb
dataConn"files/dbPoll.mdb",POdc,LArs
SelectsallfieldswithintblLanguages
LArs.Open"SELECT*FROMtblLanguages",POdc,1,2
Loopthroughandtotalupnumberofvotesforallrecords
DoWhileNotLArs.EOF
Ifrecordcontainsvotedlanguagethenincrementvotes
IfLArs("Language")=Request.Form("language")Then
LArs("Votes")=LArs("Votes")+1
LArs.Update
EndIf
I=I+LArs("Votes")
LArs.MoveNext
Loop
Calculatevaluewhichwillbeusedtocalculatepercentage
Percent=100/I
LArs.MoveFirst
Loopthroughandrecalculatepercentageofvotesforeachrecord
DoWhileNotLArs.EOF
LArs("Percentage")=LArs("Votes")*Percent
LArs.Update
LArs.MoveNext
Loop
LArs.Close
SelectsallfieldswithintblLanguages
LArs.Open"SELECT*FROMtblLanguagesORDERBYPercentageDESC",POdc
Loopthroughanddisplayallupdatedrecords
DoWhileNotLArs.EOF
Response.Write"<B>"&LArs("Language")&&</p>减少客户内IT专业人才缺乏带来的影响。ASP的客户员工利用浏览器进入相关的应用软件,简单易用,无需专业技术支持。 如何更好的使自己的东西看上去很不错等等。其实这些都不是问题的实质,我们可以在实践中不断提升自己,不断充实自己。 Request:从字面上讲就是“请求”,因此这个是处理客户端提交的东东的,例如Resuest.Form,Request.QueryString,或者干脆Request("变量名") 不是很难但是英文要有一点基础网上的教程很少有系统的详细的去买书吧,另不用专门学习vb关于vbscript脚本在asp教材都有介绍 它可通过内置的组件实现更强大的功能,如使用A-DO可以轻松地访问数据库。 Server:这个表示的服务器,操作服务器的一些东西使用这个,如Server.Mappath转换服务器路径,Server.CreateObject实例化一个组件 它可通过内置的组件实现更强大的功能,如使用A-DO可以轻松地访问数据库。 封装性使得代码逻辑清晰,易于管理,并且应用到ASP.Net上就可以使业务逻辑和Html页面分离,这样无论页面原型如何改变,业务逻辑代码都不必做任何改动;继承性和多态性使得代码的可重用性大大提高。
页:
[1]