Starting from this article, I started with ASP built-in objects and analyzed the features and methods of ASP's six built-in objects and various components in detail. Before learning ASP's built-in objects and components, let's first understand some basic concepts, which will be of great help to you in the future. See the following table:
| Active Server |
A collection of server technologies delivered with Windows NT. These technologies provide consistent server components, script models, and an integrated system service for component application management, database access, transactions, and messages. |
| Active Server Pages (ASP) |
The server script environment for running ActiveX scripts and ActiveX components on the server. Developers can combine scripts and components to create Web-based applications. |
| ActiveX |
Allows developers to create interactive components for the World Wide Web with a wide range of Microsoft technical terms. A group of language-independent interoperability technologies that allow software components written in different languages to work in the network environment. The key elements of ActiveX are Component Object Model (COM) and Distributed Component Object Model (DCOM ). These technologies have been licensed by open organizations and migrated to many platforms. |
| ADO |
Active Data Object. An object-based data access interface optimized for Internet-based data-centric applications. ADO is based on published specifications and is included in Microsoft Internet Information Server and Microsoft Visual InterDev. |
| DSN |
Data Source Name. Open Database Interface (ODBC) is used to reference the logical name of the driver or other information required to access data. The name of the Internet Information Server used to connect to an ODBC Data Source (such as an SQL Server database. |
| Event: Event |
Any operation that is responded to by a program generated by a user or ActiveX control. General events include pressing the keyboard key, clicking the select button with the mouse, and other mouse operations. Programmers write code that responds to these operations. |
| Object: Object |
In object-oriented programming, a variable consists of operations and data as a complete entity. Objects are based on specific models. In objects, customers use object services to access object data through interfaces of a set of methods or related functions. Then, the client can call these methods to perform certain operations. |
| ODBC |
Open Database Interface. Application programming interfaces that allow applications to access data from standard specifications of existing data sources for cross-platform data access. |
| SQL |
Structured Query Language: Structured Query Language. Define and access the international standards for relational databases. |
What is an object? It does not mean that you are in love with a male or female companion. In object-oriented programming, an object is a variable composed of operations and data as a complete object. Objects are based on specific models. In objects, customers use object services to access object data through interfaces of a set of methods or related functions, then the client can call these methods to perform certain operations. ActiveX components are the key to creating web applications. components provide objects for executing tasks in scripts. An ActiveX component is a file that contains the code for executing a certain item or a group of tasks. Because the component can execute public tasks, programmers do not have to create code for executing these tasks themselves. You can use components as scripts and basic construction Blocks Based on Web applications. As long as you know how to access the objects provided by the component, you can write scripts without knowing how the component works, even for beginners who write scripts. In short, components allow you to write powerful scripts without learning programming. A component is executable code contained in the dynamic link library. dll or executable file. EXE. A widget provides methods and attributes for one or more objects. To use the object provided by the component, create an instance of the object and assign the variable name to the new instance. You can use the server. Createobject method of ASP to create an object instance. You can use the Variable Allocation command in script language to name the object instance. For example: Set DB = server. Createobject ("ADODB. Connection ") The variable dB here is the object instance for accessing the database created by the ASP program. Active Server Pages provides built-in objects that can be used in scripts. These objects make it easier for users to collect information sent through browser requests, respond to browsers, and store user information. This frees object developers from a lot of tedious work. The current ASP version provides a total of six built-in objects. The following describes how to learn these objects through instances. 1. Request object You can use the request object to access all information transmitted Based on HTTP requests, including parameters, cookies, and user authentication transmitted from HTML tables using the post or get methods. The request object allows you to access the binary data sent from the client to the server. Request Syntax: Request [. Set | attribute | method] (variable) Here, the author selects some common object syntax for analysis. 1. Form The form set retrieves the values of the table elements sent to the HTTP Request body by using the POST method. Syntax Request. Form (element) [(INDEX) |. Count] Parameters Element specifies the name of the table element to be retrieved from the set. An optional index parameter. You can use this parameter to access one of multiple values of a parameter. It can be any integer between 1 and request. Form (parameter). Count. Number of elements in the count set The form set is indexed by the parameter names in the Request body. The value of request. Form (element) is an array of all element values in the Request body. Call request. Form (element). Count to determine the number of values in the parameter. If the parameter is not associated with multiple values, the count is 1. If no parameter is found, the count is 0. To reference a single value in a table element with multiple values, you must specify the index value. The index parameter can be any number from 1 to request. Form (element). Count. If you reference one of multiple table parameters without specifying the index value, the returned data is a string separated by commas. You can use a repeat to display all data values in a table request. For example, you can specify several values to enter the table. You can use the following script to retrieve the holobby parameters. <HTML> Of course, the same output can be generated using the for... next loop, as shown below: <% For I = 1 to request. Form ("holobby"). Count Response. Write Request. Form ("holobby") (I) & "<br>" next %> 2. querystring The querystring collection retrieves the value of the variable in the HTTP query string. The HTTP query string is composed of question marks (?) Specify the value after. For example: <A href = "example. asp? String = This is a sample "> string sample </a> Generate a variable name string with the value "This is a sample. You can also generate a query string by sending a table or entering a query in the address box of your browser. Syntax Request. querystring (variable) [(INDEX) |. Count] The querystring collection allows you to retrieve the QUERY_STRING variable by name. The value of request. querystring (parameter) is an array of the values of all parameters in QUERY_STRING. You can call request. querystring (parameter). Count to determine the number of parameters. You can also use querystring to achieve the same functions as the previous example. You only need to replace the request. form part with the following: <% For each I in request. querystring ("holobby ") Response. Write I & "<br>" Next %> 3. Cookies What is Cookie? A cookie is actually a tag. When you access a Web site that uniquely identifies your website, it will leave a tag on your hard disk, the next time you visit the same site, the website page will look for this tag. Each web site has its own tag, and the TAG content can be read at any time, but it can only be completed by the page of the site. The cookies of each site and the cookies of all other sites exist in different files in the same folder (you can find them in the cookie folder under the Windows directory ). A cookie is a tag that uniquely identifies a customer. A cookie can contain information shared by all pages of a Web site during a conversation or between dialogs, you can also use cookies to exchange information between pages. The cookie set provided by the request allows the user to retrieve the cookie value sent in the HTTP request. This feature is often used in ASP programs that require user authentication, as well as bulletin board, web chat rooms, etc. Syntax Request. Cookies [(key) |. Attribute] Parameters Cookie specifies the cookie whose value is to be retrieved. Key (optional) is used to retrieve the value of a subkeyword from the cookie dictionary. Attribe specifies information about the cookie itself. For example, haskeys is read-only and specifies whether the cookie contains a keyword. You can access the subkeywords of the cookie dictionary by including a key value. If no key is specified when you access the cookie dictionary, all keywords are returned as a single query string. For example, if mycookie has two keywords: first and second, and no keyword is specified when request. Cookie is called, the following string is returned. First = firstkeyvalue & Second = secondkeyvalue If the client browser sends two cookies with the same name, the request. Cookie returns a deeper path. For example, if there are two cookies with the same name, but one of the path attributes is/www/and the other is/www/home /, the client browser sends both cookies to the/www/home/directory. only the second cookie is returned. To determine whether a cookie is a cookie Dictionary (whether a cookie has a keyword), use the following script. <% = Request. Cookies ("mycookie"). haskeys %> If mycookie is a cookie dictionary, the previous value is true. Otherwise, the value is false. Let's take a look at the cookie application example: <% Nickname = request. Form ("Nick") response. Cookies ("Nick") = nickname 'Use the response object to write the user name into the cookie Response. Write "welcome" & request. Cookies ("Nick") & "Visit our website! " %> <HTML> <Title> cookie </title> <Meta name = "generator" content = "Microsoft FrontPage 3.0"> <Body> <Form method = "Post" Action = "Cookie. asp"> <P> <input type = "text" name = "Nick" size = "20"> <Input type = "Submit" value = "send" name = "B1"> <input type = "reset" value = "Refill" name = "B2"> </P> </form> </Body> This is actually a common method in Web-based BBS or chat ASP programs. It saves the user's name on the start page to the cookie, in this way, the subsequent program can easily call the user's Nick. 4. servervariables We all know that the transmission protocol used when Browsing Web pages in a browser is HTTP. Some client information, such as the customer's IP address, is recorded in the HTTP header file, sometimes the server needs to make different responses based on different client information. In this case, you need to use the servervariables set to obtain the required information. Syntax Request. servervariables (server environment variable) Due to the large number of server environment variables, the author only lists some common variables in the following table:
| All_http |
All HTTP header files sent by the client. |
| Content_length |
The length of the content sent by the client. |
| Content_type |
The data type of the content. For example, "text/html ". It is used together with the query of additional information, such as HTTP query get, post, and put. |
| Local_addr |
Returns the server address that receives the request. This variable is very important if you look for the address used by the request on a multi-host machine bound with multiple IP addresses. |
| Logon_user |
Log on to the Windows NT account. |
| QUERY_STRING |
Query question marks (?) in an HTTP request (?) . |
| Remote_addr |
The IP address of the remote host (client) that sends the request. |
| Remote_host |
The name of the host (client) that sends the request. If the server does not have this information, it will set the mote_addr variable to null. |
| Request_method |
This method is used to submit a request. It is equivalent to get, Head, post, and so on for HTTP. |
| SERVER_NAME |
The server host name, DNS alias, or IP address that appears in the Self-referenced URL. |
| Server_port |
The port number for sending the request. |
We can use the following script to print all the server environment variables. <Table> <Tr> <TD> <B> server variable </B> </TD> <B> value </B> </TD> </tr> <% for each name in request. servervariables %> <Tr> <TD> <% = Name %> </TD> <% = request. servervariables (name) %> </TD> </tr> </table> <% Next %> Today, we have learned in detail the request object in ASP built-in objects, which is also the most frequently used object in ASP programs. I hope you can practice it more after class. |