精灵巫婆 发表于 2015-1-16 22:27:26

ASP编程:一个收费的邮件列表源程序(一)

ASP最大的缺点在于网络的安全性和可靠性,企业将经营数据放在开放的平台上,最大的担忧就是如何保证这些数据不被其他人破坏。MailToList.asp
<%@Language=JavaScript%>

<!--#includefile="include/SetGlobals.asp"-->
<!--#includefile="include/DBPath.asp"-->

<%
//outputrelevantmetatags
Init("Mailtolist");

//outputcommontopofpage
Header(<ahref="work.asp">Work</a>-->Mailtolist,3);

//outputpagecontent
Content();

//outputcommonbottomofpage
Footer();
%>

<%/*standardpageelements*/%>
<!--#includefile="utils/Init.asp"-->
<!--#includefile="utils/Database.asp"-->
<!--#includefile="utils/Header.asp"-->
<!--#includefile="utils/Footer.asp"-->

<%
//============================================
//thecontentofthispage
//============================================
functionContent()
{
Out(<tdwidth="20%"></td>);
Out(<tdwidth="60%">);

//iftheformhasapassword,validateitfirst
//sothatifitfailswecanshowtheformagain
varbSubmitted=(Request.Form.Count>0);

//hastheformbeensubmitted?
if(bSubmitted)
{
//getthepasswordfromtheform...
sPassword=""+Request.Form("password");

//validatethepasswordandmoanifitfails
if(sPassword!=sDBPath)
{
Out(<h3><fontcolor="red">Invalidpassword!</font></h3>);
//pretendtheformhasn        beensentyet
bSubmitted=false;
}
}

//showtheformifnotsubmittedyet
if(!bSubmitted)
{
Out(In<ahref="Subscribe.asp">Part1</a>IshowedyouhowIallowedyoutosubscribetomymailinglist.HereswhereIcanpostanemailtomembersofthatmailinglist.);
Out(<p>Strangely,Imnotgoingtoletyoudoit,butyou<i>can</i>getthesourcecodefromthebottomofthepage,andlearnhowIdidit.);
//herestheformtag.theactionattributeisthenameof
//thefilethatwillbecalledwiththeanswer-inthiscase
//itsthesamepage.themethodcanbe"post"tosendthe
//formdatabehindthescenesor"get"toappendingthe
//datatotheURLinthestylepage.asp?data1=a&data2=b
//
//usepostmostofthetime-itsneaterand"get"islimited
//intheamountofdatathatcanbesent.
Out(<formaction="MailToList.asp"method="post">);

//anothertabletolineupthetitlesandinputs
Out(<tableborder="0"cellpadding="0">);
Out(<tr><tdalign="right"valign="top">);
Out(Password:);
Out(</td><tdalign="left"valign="top">);
//asimpletextbox.wellreferenceitwiththename"password"
//andshow37charactersontheform.usethemaxlength
//attributetosetthemaximumcharacterstheycanenter.
//usevalue="sometext"topre-filltheinputwithdata.
Out(<inputtype="password"name="password"size="30"></input>);
Out(</td></tr>);

Out(<tr><tdalign="right"valign="top">);
Out(Message:);
Out(</td><tdalign="left"valign="top">);
//textareaisamultilinetextbox.specifythesizewiththe
//colsandrowsattributes.wrapcanbe"off"(thedefault)
//"physical"or"virtual".asanexample,considertheuser
//typinginthefollowingtextina40characterwideinput:
//
//"IwonderhowthistextwillappeartotheserverwhenIsendit?"
//
//wrap="off"willsenditastyped,buttheuserhastoscrolloff
//totherighttoseethetext.(Horrid)
//
//wrap="physical"willphysicallysplitthelineaftertheword
//serverandsendtwolinestotheserver
//
//wrap="virtual"willsendoneline,astyped,buttheuser
//willseethetextnicelywrapintheinput.Perfect!
Out(<textareaname="message"cols="30"rows="8"wrap="physical"></textarea>);
Out(</td></tr>);

Out(<tr><tdalign="right"valign="top">);
Out();
Out(</td><tdalign="left"valign="top">);
//type=submit"providesasubmitbuttontoperformthe
//formaction.thebuttonsays"Submit"unlessyouoverride
//withthevalueattribute.
Out(<inputtype="submit"value="SendMail"></input>);
Out(</td></tr>);

Out(</table>);

Out(</form>);
}
else
{
//getthemessagefromtheform
varsMessage=""+Request.Form("message");

//opentheconnection
DBInitConnection();

//gettheemailsaddresses
varsSQL=SELECTEmailFROMMailingList;;

DBGetRecords(sSQL);

varsEmailList="";
varsSep="";

while(!oRecordSet.EOF)
{
sEmailList+=sSep+oRecordSet(0);

sSep=";";

oRecordSet.MoveNext();
}

//freetheconnection
DBReleaseConnection();

Email(ItsaShawThing-whatsnew?,sEmailList,sMessage);

Out(<p>Emailsentsuccessfully.<p>);
}

Out(Wanttoseehowthisformtomailthesubscriberswasdone?Clickbelowtogetallthesourcecode!);
Out(<p><center><ahref="ShowSource.asp?page=MailToList"><imgsrc="http://edu.cnzz.cn/NewsInfo/images/source.gif"border=0></a></center>);

Out(</td>);
Out(<tdwidth="20%"></td>);
}

//============================================
//emailme!
//============================================
functionEmail(sSubject,sEmail,sMessage)
{
//sendanemailtotheaddressjusttoconfirmwhatjusthappened
varoMail=Server.CreateObject("CDONTS.NewMail");

//setupthemail
oMail.From=oMail.To=MailingList@shawthing.com;

oMail.Bcc=sEmail;
oMail.Importance=1;

oMail.Subject=sSubject;
oMail.Body=sMessage;

//sendit
oMail.Send();

//releaseobject
oMail=null;
}
%>

utils/Database.asp
<%
//globals
varoConnection;
varoRecordSet;
varsConnection;

//============================================
//exampleusage:
//DBInitConnection();
//
//varsSQL="SELECT*FROMSomewhere";
//
//DBGetRecords(sSQL);
//
//...useoRecordSet
//
//DBReleaseRecords();//optionalstep
//
//DBReleaseConnection();
//============================================

//============================================
//initializesdatabasevariablesforfirstuseonpage
//============================================
functionDBInitConnection()
{
//dontopenitagainifalreadyopened!
if(sConnection!=undefined)
return;

//getconnectionobject
oConnection=Server.CreateObject(ADODB.Connection);

//getthedatabaseconnectionstring
//useMapPathtomakerelativepathintophysicalpath
sConnection=Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+Server.MapPath(sDBPath);

//opentheconnection
oConnection.Open(sConnection);

//asanattemptatoptimizationwenowopen
//therecordsethere,notinDBGetRecords()
oRecordSet=Server.CreateObject(ADODB.Recordset);
}

//============================================
//tidiesupafterDBInitConnection
//============================================
functionDBReleaseConnection()
{
//dontreleasetheconnectionifnotconnected!
if(sConnection==undefined)
return;

//asanattemptatoptimizationwenowclose
//therecordsethere,notinDBReleaseRecords()
if(oRecordSet.State!=0)
oRecordSet.Close();
oRecordSet=undefined;

oConnection.Close();
oConnection=undefined;

sConnection=undefined;
}

//============================================
//executesthepassedinSQLstatement
//andreturnstheoRecordSetobject
//============================================
functionDBGetRecords(sSQL)
{
//rememberthatthiscanfailifpassedgarbage,andhence
//oRecordSetwillalreadybeclosed
oRecordSet=oConnection.Execute(sSQL);
}

//============================================
//tidiesupafterDBGetRecords
//============================================
functionDBReleaseRecords()
{
//IMPORTANT:THISFUNCTIONINTENTIONALLYBLANK
//asanattemptatoptimizationwenowopen/close
//therecordsetwiththeconnection,notseparately
//soallcodewasmovedtoDBReleaseConnection.

//itisrecommendedthatyoustillcallthisfunctionassoon
//astherecordsetisfinishedwith.

//notethatitisassumedbythecallerthatitislegal
//tocallDBReleaseConnectionwithoutcallingthisfunction
}
%>
Windows本身的所有问题都会一成不变的也累加到了它的身上。安全性、稳定性、跨平台性都会因为与NT的捆绑而显现出来;

爱飞 发表于 2015-1-19 13:08:21

ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。

乐观 发表于 2015-1-28 07:14:34

跟学别的语言一样,先掌握变量,流程控制语句(就是ifwhileselect)等,函数/过程,数组

海妖 发表于 2015-2-5 19:41:08

在平时的学习过程中要注意现学现用,注重运用,在掌握了一定的基础知识后,我们可以尝试做一些网页,也许在开始的时候我们可能会遇到很多问题,比如说如何很好的构建基本框架。

再现理想 发表于 2015-2-13 09:41:00

作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。

变相怪杰 发表于 2015-3-3 19:51:59

接下来就不能纸上谈兵了,最好的方法其实是实践。实践,只能算是让你掌握语言特性用的。而提倡做实际的Project也不是太好,因为你还没有熟练的能力去综合各种技术,这样只能使你自己越来越迷糊。

透明 发表于 2015-3-18 20:47:57

先学习用frontpage熟悉html编辑然后学习asp和vbscript建议买书进行系统学习

谁可相欹 发表于 2015-3-26 16:34:19

ASP主要是用好六个对象,其实最主要的是用好其中两个:response和request,就可以随心所欲地控制网页变换和响应用户动作了。
页: [1]
查看完整版本: ASP编程:一个收费的邮件列表源程序(一)