1. What is VBScript?
VBScript is short for Microsoft Visual Basic Scripting Edition. You can regard it as a subset of Visual Basic, but it is just syntactically speaking, just like the relationship between JavaScript and JAVA, VBScript and Visual Basic are not essentially related. It is a script language, which is interpreted and executed by the VBScript script engine as a dynamic Connection Library VBScript. dll. Currently, it is mainly used for WWW web pages. Only IE can correctly view webpages containing VBScript. If Netscape needs to be correctly viewed, a plug-in must be installed) and Microsoft's WWW server IIS supports ASP.
The syntax of VBScript is not described here. Please refer to other books.
Ii. ASP output
Like all programming textbooks, let's start with "Hello World. Suppose we want to output "Hello World" on the webpage, which is very simple in HTML. How can we do it in ASP? See the following example:
<% Response. Write "Hello World" %>
Save it as an ASP file, and output result 1 after execution.
Here we use the Write method of the Response object. The Response object is one of the built-in ASP objects, that is, we can directly use it without creating it. ASP has six built-in objects: Server, Err, Application, Session, Request, and Response. For details about their attributes and methods, refer to the help documents of IIS or PWS.
The following is another output method:
<% = "Hello World" %>
This syntax is unique in ASP. It means to directly output the content after the equal sign "=" to the browser.
Next let's look at a slightly complex example:
<Script language = "VBScript" runat = "server">
Response. write ("1 ″)
</Script>
<% Response. write ("2") %>
<% = "3" %>
<Script language = "jscript" runat = "server">
Response. write ("4 ″);
</Script>
You may be wondering why this is not the same as the previous one. As mentioned above, ASP code should be included in <% and %>. In fact, as long as runat = "Server" is added to the <Script> label, when the WWW server encounters a script statement containing Runat = "Server, the script is interpreted on the Server side, and the role of runat = "Server" is the same as that of <%>. It is only a script environment. As for the scripting language you want to program, it is your choice. The script engine with VBscript and JScript is installed in ASP. By default, VBScript is used as the script language. However, you can use the language attribute to specify your script language. For example, you can use Multiple scripting languages in an ASP file.
Now I want to test you. What is the output of the previous example? 1234? Try it. The output is 4231 "! Originally, When IIS processes ASP files, the files are always handed over to all script engines installed on the system in sequence, and the JScript sequence is prior to VBScript. This is the reason why "4" is output at the beginning. Then, another rule is: between the Code included in $ # @ 60; script $ # @ 62; and The Code included in <%>, <%> is always processed first. Response. Write and "=" are not sorted in order and are processed in the order of appearance. This is what "23" means before "1.
3. Obtain the content SUBMITTED BY THE FORM
When surfing the internet, we often see some input boxes and buttons on some webpages. When you enter a name in the input box and press the button, the entered content will be uploaded to the server by the browser. What interacts with us on the webpage forms and uses the tag <form> in HTML. Forms are always submitted to a processing program, which can be CGI or ASP. Friends who have used CGI may know that it is very troublesome to retrieve the user's input information in the form in CGI. Some even write routines to complete the process. Then, the handler will output some prompt information and report the processing result to the user. To complete an interaction process. In ASP, all these operations become simple. See the following example.
The hypothetical server has a file form.htm, which contains only one form Image 2). The source code is as follows:
<Html>
<Body>
<Form method = "post" action = "test. asp">
Name: <input type = "input" name = "xm">
<@ 60; input type = "submit" value = "OK">
</Form>
</Body>
</Html>
After you click "OK", the form will request test. asp to process the form value. Our test. asp code is:
<%
Dim
A = Request. Form ("xm ″)
Response. Write
%>
It will display the "three" we entered on the browser side.
The Request object is used here. All the data submitted by form is saved in this object and they exist in the form of a set. The value can be retrieved using the element name. Then our program outputs it to the browser. I really want to thank the object. They have done everything for us. We only need to simply use it. Of course, we can also make test. asp do more complex tasks, such as storing the input name in the database on the server, or checking whether this person has the right to access the next page.
Well, we can finally use ASP to make interactive web pages, and it is so simple. In the next lecture, we will be exposed to the operations required by the most common applications on the Internet-database operations.