如何在ASP中实现错误陷阱技术(即实现VB中的所谓的On Error GoTo)
代码如下(一共4个文件)
1。error1.asp(用来生成错误)
<html>
<head>
<title>输入数据</title>
</head>
<body>
<form method="POST" action="error2.asp" name="form1">
<div align="left"><table border="1" width="340" height="35">
<tr>
<td width="143" height="11">喜欢的计算机</td>
<td width="185" height="11"><input type="text" name="T1" size="20"></td>
</tr>
<tr>
<td width="143" height="12">喜欢的游戏: </td>
<td width="185" height="12"><input type="text" name="T2" size="20"></td>
</tr>
</table>
</div><p>:<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset"
name="B2"></p>
</form>
</body>
</html>
2。error2.asp
<%@ Language="vbscript"%>
<%
Response.buffer = True
On Error Resume Next
dim conn
dim rs
set conn = server.createobject("adodb.connection")
conn.open "Example_DSN"
If err.number <> 0 Then
Response.Redirect "Error3.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
End If
set rs = server.createobject("adodb.recordset")
rs.open "TableName", conn, 3, 3
If err.number <> 0 Then
Response.Redirect "Error3.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
End If
rs.addnew
rs("field1") = request.form("field1")
rs("field2") = request.form("field2")
rs.update
If err.number <> 0 Then
Response.Redirect "Error3.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
End If
rs.close
conn.close
set rs = nothing
set conn = nothing
%>
<html>
<head>
<title>成功</title>
</head>
<body>
<p>操作完成!</p>
</body>
</html>
3。error3.asp
<%@ language="vbscript"%> <%
response.buffer = True
dim strNumber
dim strdesc
dim conn
dim rs
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("error.mdb")
strNumber = request("Number")
strDesc = request("Desc")
set conn = server.createobject("adodb.connection")
conn.open strconn
set rs = server.createobject("adodb.recordset")
rs.open "tblError", conn , 2, 2
rs.addnew
rs("ErrNumber") = strNumber
rs("ErrDesc") = strDesc
rs("timeoccurred") = now()
rs.update
rs.movelast
strID = rs("id")
rs.close
set rs = nothing
conn.close
set conn = nothing
err.clear
%> </p>
<html>
<head>
<title>出错页面</title>
</head>
<body>
<h1>发生错误</h1>
<h2>错误 ID 为:<% = strID %></h2>
<h3>错误号为:&l