From the beginning of this article, the author starts from the ASP, and analyzes the characteristics and methods of the ASP's six built-in objects and various components in detail.
Before we begin to learn the ASP's built-in objects and components, let us understand some basic concepts, which will be of great help to you in your future study. Take a look at the following table:
Active Server |
A collection of server-side technologies delivered with Windows NT. These technologies provide consistent server-side components, scripting models, and a set of integrated system services for component application management, database access, transactions, and messaging. |
Active Server Pages (ASP) |
A server-side scripting environment that runs ActiveX scripts and ActiveX components on the server. Developers can combine scripts and components to create web-based applications. |
Activex |
The rich Microsoft technical terminology that allows developers to create interactive components for the world Wide Web. A set of language-independent interoperability technologies that allow software components written in different languages to work together in a networked environment. The key elements of ActiveX are the Component Object Model (COM) and the Distributed Component Object Model (DCOM). These technologies have been licensed by open organizations and have been ported to many platforms. |
Ado |
An Active data object. A set of object-based data access interfaces optimized for data-centric applications based on the Internet. ADO is based on published specifications and is shipped with Microsoft Internet Information Server and Microsoft Visual InterDev. |
Dsn |
The name of the data source. Open Database Interface (ODBC) is used to reference the logical name of the driver or other information required to access the data. The name used by an Internet Information Server to connect to an ODBC data source, such as a SQL Server database. |
Event: Events |
Any action that the program responds to by a user or ActiveX control. General events include pressing keyboard keys, selecting buttons by using the mouse click, and other mouse actions. Programmers write code that responds to these actions. |
Object: Objects |
In object-oriented programming, a variable consisting of operations and data as a complete entity. Objects are based on a specific model in which the client uses the object's services to access the object's data through an interface of a set of methods or related functions. The client can then call these methods to perform an operation. |
Odbc |
Open Database interface. An application programming interface that allows applications to access data from the standard specifications of existing data sources that are accessed from a variety of cross-platform data. |
Sql |
The Structured Query language is structured query Language. Defines and accesses international standards for relational databases. |
What is an object? It's not about your partner or girlfriend you're in love with. In object-oriented programming, an object is a variable consisting of operations and data as a complete entity. Objects are based on a specific model in which the client uses the object's services to access the data of the object through an interface of a set of methods or related functions, and the client can then call these methods to perform an operation. ActiveX components are the key to building WEB applications, and components provide the objects that perform tasks in scripts. An ActiveX component is a file that contains code to perform an item or a set of tasks, because the components can perform common tasks so that programmers do not have to create the code to perform those tasks themselves. You can leverage components as scripts and basic building blocks for web-based applications. As long as you know how to access the objects that the component provides, even a novice who writes scripts can write scripts without knowing how the components work. In summary, components enable you to write powerful scripts without learning to program. A component is an executable code contained in a dynamic-link library. dll or executable file. exe. A component can provide one or more objects and the methods and properties of an object. To use the object provided by the component, create an instance of the object and assign the new instance to the variable name. Using the ASP's Server.CreateObject method to create an instance of an object, a variable assignment instruction using a scripting language can be named for an object instance. The following example:
Set db=server.createobject ("ADODB. Connection ")
The variable db here is the object instance that the ASP program creates to access the database.
Active Server Pages provides built-in objects that you can use in scripts. These objects make it easier for users to gather information that is sent through a browser, respond to browsers, and store user information, thereby getting the object developer out of a lot of tedious work. The current ASP version provides a total of six built-in objects, let's go through the examples to learn separately.
One, Request object
You can use the request object to access any information that is delivered based on an HTTP request, including parameters, cookies, and user authentication that are passed from the HTML table using the POST method or the Get method. The Request object enables you to access the binary data that the client sends to the server.
Syntax for Request:
Request[. Collection | properties | methods] (variables)
Here the author will pick some common object syntax to analyze
1, Form
The form collection retrieves the values of the table elements that are sent to the body of the HTTP request by using the form of the POST method.
Grammar
Request.Form (Element) [(index) |. Count]
Parameters
element specifies the name of the table element to retrieve for the collection.
The index optional parameter, which you can use to access one of several values in a parameter. It can be 1 to request.form (parameter). Any integer between Count.
Number of elements in the Count collection
The Form collection is indexed by the name of the parameter in the body of the request. The value of Request.Form (element) is an array of all element values in the request body. by calling Request.Form (element). Count to determine the number of values in the parameter. If the parameter is not associated with more than one value, the count is 1. If the argument is not found, the count is 0. To reference a single value in a TABLE element that has multiple values, you must specify the index value. The index argument can be from 1 to Request.Form (element). Any number in Count. If you refer to one of several table parameters without specifying the index value, the returned data will be a comma-delimited string.
You can use the Restatement character to display all the data values in the table request. For example, the user fills out a form by specifying several values, as shown in the following figure.
For hobby parameters, you can use the following script to retrieve these values. < html> < head>< title></title>
Clip the above code into a notepad (note that the space after "<" is removed), save it as a form.asp file and run, and the request object can display the elements one at a different basis depending on how you fill in the form or select the element content.
Of course use for ... The next loop can also generate the same output, as follows:
<%
For i = 1 to Request.Form ("hobby"). Count
Response.Write Request.Form ("hobby") (i) & "< br>" Next
%>
2, QueryString
The QueryString collection retrieves the value of a variable in an HTTP query string that is specified by the value of the question mark (?). Such as:
< a href= "Example.asp?string=this is a sample" >string sample</a>
Generates a variable name string with the value "This is a sample". You can also generate a query string by sending a table or by typing a query in the Address box of the user's browser.
Grammar
Request.QueryString (variable) [(index) |. Count]
The QueryString collection allows you to retrieve query_string variables by name. The value of the Request.QueryString (parameter) is an array of values that appear in all parameters in Query_string. by calling Request.QueryString (parameter). Count can determine how many values a parameter has.
We can also use QueryString to achieve the same functionality as the previous example. You only need to replace the Request.Form section as follows:
<%
For all I in Request.QueryString ("hobby")
Response.Write I & "< br>"
Next
%>
3. Cookies
What is a Cookie? A Cookie is actually a tag, and when you visit a Web site that needs to uniquely identify your site, it leaves a mark on your hard drive, and the next time you visit the same site, the site's page looks for the tag. Each WEB site has its own tag, and the tagged content can be read at any time, but only by the page of that site. Cookies for each site exist within different files in the same folder as all other site cookies (you can find them in the Cookies folder in the Windows directory). A cookie is a token that uniquely identifies a customer, and a cookie can contain information that is shared by all pages of a WEB site during a conversation or several conversations, and can also be exchanged between pages using cookies. The collection of cookies provided by request allows the user to retrieve the value of the cookie sent in the HTTP request. This feature is often used in ASP programs that require authentication of customer passwords as well as electronic bulletin boards, WEB chat rooms, and so on.
Grammar
Request.Cookies (cookie) [(key) |. Attribute
Parameters
The cookie specifies the cookie whose value you want to retrieve.
The key optional parameter that retrieves the value of the subkey from the cookie dictionary.
ATTRIBE specifies information about the cookie itself. such as: HasKeys Read Only, specifies whether the cookie contains keywords.
You can access the child keywords of the cookie dictionary by including a key value. If key is not specified when accessing the cookie dictionary, all keywords are returned as a single query string. For example, if MyCookie has two keywords, first and second, and does not specify any of these keywords when calling Request.Cookies, the following string is returned.
First=firstkeyvalue&second=secondkeyvalue
If the client browser sends two cookies with the same name, then Request.cookie returns one of the deeper path structures. For example, if you have two cookies with the same name, but one of the path properties is/www/and the other is/www/home/, and the client browser sends two cookies to the/www/home/directory at the same time, Request.cookie will return only the second C Ookie.
To determine whether a cookie is a cookie dictionary (whether a cookie has keywords), use the following script.
<%= request.cookies ("MyCookie"). HasKeys%>
If MyCookie is a cookie dictionary, the previous assignment is TRUE. Otherwise, FALSE. Now let's take a look at a cookie application example:
<%
Nickname=request.form ("Nick") Response.Cookies ("Nick") =nickname ' writes the username to the Cookie with response object Response.Write ' Welcome &request.cookies ("Nick") & "visit the station!" "
%>
< html>< head>< Meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 ">
< 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= ">"
< input type= "submit" value= "send" Name= "B1" >< input type= "reset" value= "refill" name= "B2" ></p></form >
</body>
This is in fact a web-based BBS or CHAT ASP program is commonly used in the method, it will be the user in the start page filled in the name of the cookie, so that the subsequent program can easily invoke the user's nick.
4, ServerVariables
We all know that when browsing the Web page in the browser, the use of the transport Protocol is HTTP, in the HTTP header file will record some client information, such as: Customer's IP address, and so on, sometimes server-side needs to be based on different client information to make a different response, this time need to use ServerVariables collection to obtain the required information.
Grammar
Request.ServerVariables (server environment variable)
Because of the large number of server environment variables, the author only lists some commonly used variables in the following table:
All_http |
All HTTP header files sent by the client. |
Content_length |
The length of the content that the client emits. |
Content_Type |
The data type of the content. such as: "text/html". Used with queries with additional information, such as HTTP query get, POST, and put. |
Local_addr |
Returns the server address that accepts the request. This variable is important if the address used by the request is found on a multihomed machine that binds multiple IP addresses. |
Logon_User |
User logged in to the Windows NT account. |
Query_string |
Query the information after the question mark (?) in the HTTP request. |
Remote_addr |
The IP address of the remote host (client) that issued the request. |
Remote_host |
The host (client) name that issued the request. If the server does not have this information, it will be set to an empty mote_addr variable. |
Request_method |
This method is used to make a request. The equivalent of, post, etc. for HTTP. |
server_name |
The server host name, DNS alias, or IP address that appears in the self-referencing URL. |
Server_port |
The port number on which the request was sent. |
We can print out all the server environment variables using the following script.
< table>
< tr>< td>< b>server variable</b></td>< td>< b>value</B></TD>& Lt /tr><% for per name in Request.ServerVariables%>
< tr>< td> <%= name%> </td>< td> <%= request.servervariables (name)%> </td> </tr></table>
<% Next%>
today, we studied the ASP in detail in the object of the request object, this is the ASP program to use the most frequent objects, I hope everyone in the class after a lot of practice.