About ASP Object Explanation (vomiting blood to the big broadcast)

Source: Internet
Author: User
Object what is an object? 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.



4.1 ASP Built-in Object request



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 you 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 hobby parameters, you can use the following script to retrieve these values.






<body>

<p> please fill in your hobby </p>

<form method= "POST" action= "form.asp" >

<p><input type= "text" name= "hobby" size= "><br>"

<input type= "checkbox" name= "Hobby" value= "Football" > Football

<input type= "checkbox" name= "Hobby" value= "Table tennis" > table tennis </p> <p>

<input type= "Submit" value= "send" Name= "B1" >

<input type= "reset" value= "refill" name= "B2" ></p>

</form>

<% for each I in Request.Form ("hobby") Response.Write I & "<BR>" Next

%>

</body>



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=



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.