仓酷云

标题: ASP编程:ASP中的毛病代码技能 [打印本页]

作者: 再现理想    时间: 2015-1-16 23:15
标题: ASP编程:ASP中的毛病代码技能
ASP在国内异常流行,因为国内大多使用的是盗版的Windows和盗版的SQLServer,而ASP+COM+SQLServer实际上也是一种不错的搭配,其性能也不输于PHP+MYSQL,特别是Windows系统和SQLServer都有图形界面,比APACHE和MYSQL易于维护,因此对于不重视知识产权的国家来说也是一种不错的选择。毛病|技能WhenerrorcodinginASPit’snotasrichanenvironmentasotherenvironments.Ireallyonlyreports
thattherewasanerrorwithsomeNumbersandDescriptions.ThereisonlyafewwaysIvefoundto
reporttheseerrorsbacktotheenduser.Iveseennumerouswaysofdoingitbutfoundthiswaythe
mostgraceful.Rememberyouhavetoexplicitlycheckaftereverythingthatmightcauseanerror.The
mainonesIveexperiencesaredatabaseopeningsandrecordsetopenings&updates.Hereisthesample
codeIusetocheckforerrorsandthenredirectthemtotheerrorpageandrecordtheerrorintoa
database..Notethatallmyerrorcheckingisdonebeforethe<html>headeriswrittensoifthereisan
erroritcanredirectthepagewithoutgettinganerrorofHeadingalreadywrittentotheclient.Ifthe
htmlheaderhasbeensenttotheclientyoucantdoaresponse.redirectcommand.

Page1AsampleActiveServerPageformyouwouldusetosubmitdata

<html>

<head>
<title>Entersomedataintothefield</title>
</head>

<body>

<p>Entersomedataintothefield.Thisformisnothingmorethanrepresentinga
formyouwoulduseinreallifetosubmitsomedatatoanASPpage.Notethis
isntgoingtoenterthedataintodatabasebutitwillrecordtheerroronanErrorpage
andthenthesomeinformationabouttheError.</p>

<formmethod="POST"action="error2.asp"name="form1">
<divalign="left"><tableborder="1"width="340"height="35">
<tr>
<tdwidth="143"height="11">FavoriteComputer</td>
<tdwidth="185"height="11"><inputtype="text"name="T1"size="20"></td>
</tr>
<tr>
<tdwidth="143"height="12">FavoriteGame:</td>
<tdwidth="185"height="12"><inputtype="text"name="T2"size="20"></td>
</tr>
</table>
</div><p>:<inputtype="submit"value="Submit"name="B1"><inputtype="reset"value="Reset"
name="B2"></p>
</form>
</body>
</html>

Page2theformthatisbeingsubmittedtoandalsogeneratestheerrorthat
redirectsittotheStandardErrorPage(WhichisPage3inthisexample)

<%@Language="vbscript"%>
<%
Holdthepageinmemoryuntilresponse.flushcommandisissuedorthe</html>tagisprocessed.
Response.buffer=True

Thisforcesthepagetocontinuetoprocesseventhoughtherewasanerror.
OnErrorResumeNext

Declareallvariables
dimconn
dimrs
setconn=server.createobject("adodb.connection")
conn.open"Example_DSN"

StandardErrorcodingifthedatabasewontopenanerrornumberwillreturnsomethingelsebutzero
Ithencapturetheerrornumberanddescriptionandispassedusingthequerystringmethod
NotethedescriptionisusingtheServer.URLEncodefunction(Thiswillfillanyspacesinthe
descriptionwith
thecorrectHTMLcode
Iferr.number0Then
Response.Redirect"Error3.asp?number="&err.Number&"&desc="&Server.URLEncode(err.description)
EndIf
setrs=server.createobject("adodb.recordset")
rs.open"TableName"conn33
Explicitlycheckstoseeifthereisaproblemopeningthetable
Iferr.number0Then
Response.Redirect"Error3.asp?number="&err.Number&"&desc="&Server.URLEncode(err.description)
EndIf

rs.addnew
rs("field1")=request.form("field1")
rs("field2")=request.form("field2")
rs.update

Explicitlycheckstoseeifthereisaproblemupdatingtherecord
Iferr.number0Then
Response.Redirect"Error3.asp?number="&err.Number&"&desc="&Server.URLEncode(err.description)
EndIf
rs.close
conn.close
setrs=nothing
setconn=nothing
%>
<html>
<head>
<title>Recordsbeenadded</title></p>ActiveServerPage技术为应用开发商提供了基于脚本的直观、快速、高效的应用开发手段,极大地提高了开发的效果。在讨论ASP的安全性问题之前,让我们来看看ASP是怎么工作的。
作者: 飘灵儿    时间: 2015-1-20 08:45
作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。
作者: 冷月葬花魂    时间: 2015-1-29 06:16
Request:从字面上讲就是“请求”,因此这个是处理客户端提交的东东的,例如Resuest.Form,Request.QueryString,或者干脆Request("变量名")
作者: 第二个灵魂    时间: 2015-2-5 23:05
ASP(ActiveServerPages)是Microsfot公司1996年11月推出的WEB应用程序开发技术,它既不是一种程序语言,也不是一种开发工具,而是一种技术框架,不须使用微软的产品就能编写它的代码,能产生和执行动态、交互式、高效率的站占服务器的应用程序。
作者: 愤怒的大鸟    时间: 2015-2-14 02:40
还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。
作者: 只想知道    时间: 2015-3-4 04:15
作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。
作者: 金色的骷髅    时间: 2015-3-11 16:26
代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。
作者: 柔情似水    时间: 2015-3-19 02:11
学习ASP其实应该上升到如何学习程序设计这种境界,其实学习程序设计又是接受一种编程思想。比如ASP如何学习,你也许在以前的学习中碰到过。以下我仔细给你说几点:




欢迎光临 仓酷云 (http://ckuyun.com/) Powered by Discuz! X3.2