Starting from this section, I will introduce to you a few of the three general classes in ASP. It runs through the three-layer architecture I designed and is an extension of the ASP syntax, which can improve the efficiency of processing many details, and can be regarded as a little bit of the framework.
This section introduces the error handling class, the class name Con_Error, which is initialized at the beginning of the code page. The instance name is e. The following e.add is used to operate using the instantiated object of the error class.
Method introduction:
e.Add(ByVal vErrorMessage) records an error and sets e.Error = true. When an error is found in the program to detect the username legality, this method is called to record an error message.
For example, if the user logs in with the wrong password, then call e.add("Your account or password is wrong"). At this time, an error is recorded in the error object e, and the attribute e.Error=true of the error object. In subsequent operations, this attribute of the error object can be used for judgment.
For example:
After an error occurs, a small window pops up and prompts an error, and returns to the previous page.
if e.Error then
e.Alert_Back "Please log in again!" 'The role of Alert_Back is introduced later.
end if
e.Alert_Back(ByVal vMessage) Use Javascript to pop up an error message box, displaying all the current error list. The vMessage in Alert_Back(vMessage) is displayed on the last line, which is used to prompt the user to take steps after seeing this error message. And return to the previous page. The code of this method is posted, and everyone will understand better:
Public Sub Alert_Back(ByVal vMessage)
strJSMessage = JSMessage & vMessage 'JSMessage is used to store the error list in the e object, and each error is separated by /n.
%>
<script language="javascript" >
<!--//
alert("<%=strJSMessage %>"); 'The prompt error box pops up.
history.back(); 'Return to the previous page
//-->
</script>
<%
response.end 'Note that you should stop the output here to avoid errors while the program continues to execute.
End Sub
The e.Alert_Back method extends several methods with similar effects, as described below. Please refer to the additional source code for the implementation process:
e.Alert(ByVal vMessage) Only an error message box pops up, does not return to the previous page, and does not stop the execution of the program.
e.Alert_Close(ByVal vMessage) An error message box pops up. When the user clicks OK, close the current window.
e.OK_Go(ByVal vMessage,ByVal vURL) A message prompt box pops up. When the user clicks OK, jump to the vURL page.
e.Go(ByVal vURL) jumps directly to the vURL page
Everyone should be familiar with the functions of the above methods, but in fact they are not limited to error handling.
e.Clear Clear error information recorded in the error object, e.Error = false
Because the e object is a global object, it may be called in many processes. When you only need to count the errors in a certain module, you can start calling this method to clear the errors in e.
The following are packaging for Response.Write, the purpose is only for convenience and speed during use.
e.Debug (ByVal vMessage) outputs debugging information. When the program is completed, there will be many error debugging information output using Response.write, which must be deleted and carefully searched. Use e.Debug to output debugging information specifically. When the program is completed, you only need to search for e.Debug to find the location of all debugging error information.
ew(ByVal vMessage) output information. It is just a simple wrapper of Response.write. Entering ew in the program is not much more convenient than entering Response.write, and it is always easy to write incorrectly.