仓酷云

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

[学习教程] ASP编程:ASP中的毛病代码技能

[复制链接]
再现理想 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 23:15:58 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

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

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

x
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是怎么工作的。
柔情似水 该用户已被删除
8#
发表于 2015-3-19 02:11:55 | 只看该作者
学习ASP其实应该上升到如何学习程序设计这种境界,其实学习程序设计又是接受一种编程思想。比如ASP如何学习,你也许在以前的学习中碰到过。以下我仔细给你说几点:
金色的骷髅 该用户已被删除
7#
发表于 2015-3-11 16:26:01 | 只看该作者
代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。
只想知道 该用户已被删除
6#
发表于 2015-3-4 04:15:09 | 只看该作者
作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。
愤怒的大鸟 该用户已被删除
5#
发表于 2015-2-14 02:40:11 | 只看该作者
还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。
第二个灵魂 该用户已被删除
地板
发表于 2015-2-5 23:05:44 | 只看该作者
ASP(ActiveServerPages)是Microsfot公司1996年11月推出的WEB应用程序开发技术,它既不是一种程序语言,也不是一种开发工具,而是一种技术框架,不须使用微软的产品就能编写它的代码,能产生和执行动态、交互式、高效率的站占服务器的应用程序。
冷月葬花魂 该用户已被删除
板凳
发表于 2015-1-29 06:16:34 | 只看该作者
Request:从字面上讲就是“请求”,因此这个是处理客户端提交的东东的,例如Resuest.Form,Request.QueryString,或者干脆Request("变量名")
飘灵儿 该用户已被删除
沙发
发表于 2015-1-20 08:45:37 | 只看该作者
作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-9-21 10:41

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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