Some previously collected data---How to implement error trap technology in ASP

Source: Internet
Author: User
Tags implement reset urlencode
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>
&LT;TD width= "143" height= "one" > Favorite computer </td>
&LT;TD width= "185" height= "one" ><input type= "text" name= "T1" size= "></td>"
</tr>
<tr>
&LT;TD width= "143" height= "a" > Favorite Games: </td>
&LT;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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.