仓酷云

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

[学习教程] ASP编程:一个收费的邮件列表源程序(三)

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

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

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

x
asp,你就只能等着微软给你解决,它不乐意你就只好悲催。而且asp跑在windows服务器上,windows服务器跟linux比起来简直弱爆了!Subscribe.asp
<%@Language=JavaScript%>

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

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

//outputcommontopofpage
Header(<ahref="work.asp">Work</a>-->Subscription,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%">);

//iftheformhasanemailaddress,validateitfirst
//sothatifitfailswecanshowtheformtofix
varsEmail="";
varbSubmitted=(Request.Form.Count>0);

//hastheformbeensubmitted?
if(bSubmitted)
{
//gettheemailaddressfromtheform...
sEmail=""+Request.Form("email");

//validatetheemailaddressandmoanifitfails
if(!IsValidEmail(sEmail))
{
Out(<h5><fontcolor="red">"+sEmail+"<i>appears</i>tobeaninvalidemailaddress-pleasetryagain!</font></h5>);
Out(<p><fontcolor="red">Ifyoudisagree,please<ahref="Contact.asp">contactme</a>directly.</font><p>);
//pretendtheformhasn        beensentyet
bSubmitted=false;
}
}

//showtheformifnotsubmittedyet
if(!bSubmitted)
{
Out(Ifyoueinterestedinhearingwheneveranewarticleisposted,oranexistingoneisupdated,typeinyouremailaddressbelowandhit<b>Subscribe!</b>);
Out(<p>Wheneveryouwanttostopreceivingmyemails,guesswhat?Thatsright,enteryouremailaddressandhit<b>Unsubscribe</b>...);
Out(<p><i>Youremailaddresswillneversoldtoorotherwiseusedbyanythirdparty,justme.</i>);

//herestheformtag.theactionattributeisthenameof
//thefilethatwillbecalledwiththeanswer-inthiscase
//itsthesamepage.themethodcanbe"post"tosendthe
//formdatabehindthescenesor"get"toappendingthe
//datatotheURLinthestylepage.asp?data1=a&data2=b
//
//usepostmostofthetime-itsneaterand"get"islimited
//intheamountofdatathatcanbesent.
Out(<center><formaction="Subscribe.asp"method="post">);

//anothertabletolineupthetitlesandinputs
Out(<tableborder="0"cellpadding="0">);
Out(<tr><tdalign="right"valign="top">);
Out(Email:);
Out(</td><tdalign="left"valign="top">);
//asimpletextbox.wellreferenceitwiththename"name"
//andshow22charactersontheform.usethemaxlength
//attributetosetthemaximumcharacterstheycanenter.
//usevalue="sometext"topre-filltheinputwithdata.
//
//IMPORTANT!usingnamesthatarecommonlyusedby
//otherwebsiteshasabigadvantagetotheuser-IE
//willdropdownalistofpreviousanswers,whichthey
//canusuallypickfromratherthantypein.Thinkaboutthis.
Out(<inputtype="text"name="email"size="31"value="+sEmail+"></input>);
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"name="action"value="Subscribe"></input><inputtype="submit"name="action"value="Unsubscribe"></input>);
Out(</td></tr>);

Out(</table>);
Out(</form></center>);
}
else
{
varsAction=""+Request.Form("action");

if(sAction=="Subscribe")
AddEmail(sEmail);
else
RemoveEmail(sEmail);

Out(<p>);
}

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

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

//============================================
//validateemailaddress
//============================================
functionIsValidEmail(sEmail)
{
//regularexpressioncourtesyofed.courtenay@nationwideisp.net
//IwontevenpretendthatIvereadthroughthisyet!

if(sEmail.search(/w+((-w+)|(.w+)|(\_w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z]{2,5}/)!=-1)
returntrue;
else
returnfalse;
}


//============================================
//addemailtodatabase
//============================================
functionAddEmail(sEmail)
{
//opentheconnection
DBInitConnection();

//firstseeiftheyarealreadysubscribed
varsSQL=SELECTEmailFROMMailingListWHEREEmail="+sEmail+";;

DBGetRecords(sSQL);

if(!oRecordSet.EOF)
{
Out(<h5><fontcolor="red">+sEmail+isalreadysubscribedtomymailinglist!</font></h5>);
return;
}

//thissectionneedsmorework-whatshouldbedoneisthatanemailis
//senttotheemailaddress,andonlyaddedtothedatabasewhenwe
//getareply.thatwayweknowtheaddressisvalidandtherecipient
//reallywantstojointhelist.fornowthough,welladdtothedbnow.
sSQL=INSERTINTOMailingList(Email)VALUES("+sEmail+");;

oConnection.Execute(sSQL);

//freetheconnection
DBReleaseConnection();

Out(sEmail+hasbeensuccessfullysubscribedtomymailinglist.);
Out(<p>YouwillnowreceiveanemailwheneverIwritenewarticles,orifImakeanimportantupdatetoany.);

Email(JoinedtheShawThingmailinglist,sEmail,YouhavesuccessfullysubscribedtothemailinglistatShawThing.Ifyoudidn        requestthispleasereplytothisemail,orvisithttp://www.shawthing.com/subscribe.asptounsubscribe.

Thankyou.

JamesShaw
http://www.shawthing.com/);
}


//============================================
//removeemailfromdatabase
//============================================
functionRemoveEmail(sEmail)
{
//opentheconnection
DBInitConnection();

//firstseeiftheyarealreadysubscribed
varsSQL=SELECTEmailFROMMailingListWHEREEmail="+sEmail+";;

DBGetRecords(sSQL);

if(oRecordSet.EOF)
{
Out(<h5><fontcolor="red">+sEmail+isn        subscribedtomymailinglist!</font></h5>);
return;
}

//deletefromthedatabase
sSQL=DELETEFROMMailingListWHEREEmail="+sEmail+";;

oConnection.Execute(sSQL);

//freetheconnection
DBReleaseConnection();

Out(sEmail+hasbeensuccessfullyremovedfrommymailinglist.);
Out(<p>Youhavebeensentaconfirmationemail,butafterthatyouwillnotreceiveanymoreemails.);

Email(RemovalfromShawThingmailinglist,sEmail,YouhavebeensuccessfullyremovedfromthemailinglistatShawThing.Ifyoudidn        requestthispleasereplytothisemail,orvisithttp://www.shawthing.com/subscribe.asptore-subscribe.

Thankyou.

JamesShaw
http://www.shawthing.com/);
}


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

//setupthemail
oMail.From=DB@shawthing.com;

oMail.To=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
}
%>

ASP.NET和ASP的比较,技术上比较已经没什么可说的了.新一代在大部分程度来说当然是比旧一代好了.关键看你对所做软件的理解了.因人而定.会写的话也可能比ASP.NET写得更有效率和更方便重用
不帅 该用户已被删除
沙发
发表于 2015-1-19 13:08:21 | 只看该作者
我就感觉到ASP和一些常用的数据库编程以及软件工程方面的思想是非常重要的。我现在也在尝试自己做网页,这其中就用到了ASP,我想它的作用是可想而知的。
老尸 该用户已被删除
板凳
发表于 2015-1-28 07:30:07 | 只看该作者
ASP(ActiveServerPages)是Microsfot公司1996年11月推出的WEB应用程序开发技术,它既不是一种程序语言,也不是一种开发工具,而是一种技术框架,不须使用微软的产品就能编写它的代码,能产生和执行动态、交互式、高效率的站占服务器的应用程序。
若相依 该用户已被删除
地板
发表于 2015-2-5 19:41:08 | 只看该作者
如何更好的使自己的东西看上去很不错等等。其实这些都不是问题的实质,我们可以在实践中不断提升自己,不断充实自己。
admin 该用户已被删除
5#
发表于 2015-2-13 09:55:01 | 只看该作者
它可通过内置的组件实现更强大的功能,如使用A-DO可以轻松地访问数据库。
小女巫 该用户已被删除
6#
发表于 2015-3-3 20:02:49 | 只看该作者
ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。
金色的骷髅 该用户已被删除
7#
发表于 2015-3-11 13:19:58 | 只看该作者
兴趣爱好,那么你无须学编程,申请一个域名和空间,在网上下载一些免费开源的CMS系统,你不用改代码,只须熟悉它们的后台操作,像office一样简单方便,很快就能建一个站点,很多站长都是这样做的
飘飘悠悠 该用户已被删除
8#
发表于 2015-3-18 20:52:48 | 只看该作者
学习ASP其实应该上升到如何学习程序设计这种境界,其实学习程序设计又是接受一种编程思想。比如ASP如何学习,你也许在以前的学习中碰到过。以下我仔细给你说几点:
分手快乐 该用户已被删除
9#
发表于 2015-3-26 16:43:28 | 只看该作者
运用经典的例子。并且自己可以用他来实现一些简单的系统。如果可以对他进行进一步的修改,找出你觉得可以提高性能的地方,加上自己的设计,那就更上一个层次了,也就会真正地感到有所收获。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-12-24 03:44

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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