Error how to implement error trap technology in ASP (that is, realize the so-called On Error GoTo in VB)
The code is as follows (altogether 4 files)
1. Error1.asp (used to generate errors)
<title> input Data </title>
<body>
<form method= "POST" action= "error2.asp" Name= "Form1" >
Align= "left" ><table border= "1" width= "<div" height= ">"
<tr>
<TD width= "143" height= "one" > Favorite computer </td>
<TD width= "185" height= "one" ><input type= "text" name= "T1" size= "></td>"
</tr>
<tr>
<TD width= "143" height= "a" > Favorite Games: </td>
<TD width= "185" height= "><input type=" text "name=" T2 "size=" ></td>
</tr>
</table>
</div><p>:<input type= "Submit" value= "Submit" Name= "B1" ><input "reset" type= "reset"
Name= "B2" ></p>
</form>
</body>
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
%>
<title> Success </title>
<body>
<p> Operation completed!</p>
</body>
3. Error3.asp
<%@ language= "VBScript"%> <%
Response.Buffer = True
Dim strnumber
Dim Strdesc
Dim conn
Dim rs
strconn = "Driver=microsoft Access DRIVER (*.mdb);D bq=" & 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>
<title> error Page </title>
<body>
<i><% = Strnumber%>
</i>
<i><% = Strdesc%>
</i>
</body>
4. A database for logging errors (Access)
Total errnumber,errdesc,timeoccurred three fields