|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
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写得更有效率和更方便重用 |
|