ASP Basics Tutorial: ASP Built-in Object Request
0 comments
From the beginning of this started from the ASP built-in objects, as we detailed analysis of the six built-in ASP objects and features of various components and methods.
Started learning in the built-in ASP objects and components before, let us know some basic concepts, which will greatly help you in the future of learning. See the following table:
Active Server with Windows NT server side technology to deliver a collection. The application of these technologies for the management of components, database access, services and information to provide a consistent server-side components, scripts, models and a set of integrated system services.
Active Server Pages (ASP) run on the server ActiveX Scripting and ActiveX components, server-side scripting environment. Developers can integrate the script and components to create Web-based applications.
ActiveX allows developers to create interactive World Wide Web component of the content-rich Microsoft technical terms. Allows software components written in different languages to work together in a network environment is not dependent on a group of language interoperability technology. The key elements ActiveX Component Object Model (COM) and distributed component object model (DCOM). These techniques have been open licensing organization, has ported to many platforms.
ADO Active Data Objects. Internet-based data-centric applications and the optimization of a set of object-based data access interface. ADO based on published specifications and comes with the Microsoft Internet Information Server and Microsoft Visual InterDev in.
Data Source Name DSN. Open database interface (ODBC) to access the data required for the reference driver or other information logical name. Internet Information Server to connect to ODBC data sources (such as SQL Server database) name.
event: Event generated by the user or the ActiveX control procedures to respond to any action. General events, including keyboard keys, by using the mouse click the Select button and the other mouse. Programmers to write code to respond to these operations.
object: objects in object-oriented programming, as a complete entity by the operation and composition of variable data. Object is based on the specific model, the object of service customer to use an object through a method or correlation function of a set of interfaces to access object data. The client then can call these methods in the implementation of an operation.
ODBC Open Database Interface. Allow applications from a variety of cross-platform data access available data sources to access data in standard application programming interface.
SQL Structured Query Language Structured Query Language. Relational database definition and access to international standards.
What is the object? It’s not that you love the male partner or companion. In object-oriented programming, objects that means as a complete entity consisting of operations and data variables. Object is based on the specific model, the object of service customer to use an object through a method or correlation function of a set of interfaces to access the data object, then the client can call these methods in the implementation of an operation. ActiveX component is to build Web applications key component provides the implementation of tasks in the script object. ActiveX component is a file that contains the implementation of a code or set of tasks, because components can perform common tasks, so programmers do not have to create their own code to perform these tasks. Components can be used as a script-based Web applications the basic building block. As long as know how to access component provides objects, even if scripting is a novice, do not understand the components can operate in case of script. In summary, the component so that you do not learn programming can write a powerful script. Components are included in the dynamic link library. Dll or executable file. Exe in the executable code. Components can provide one or more objects and methods and properties. To use the component provides an object, create an instance of an object and assign the new instance variable name. Use ASP’s Server.CreateObject method to create an instance of an object, use the scripting language instruction can be assigned a variable named object instance. The following cases:
Set db = Server.CreateObject (“ADODB.Connection”)
Db variable here is the ASP program created to access the database object instance.
Active Server Pages provide script that can be used in built-in object. These objects make it easier for users to send a request through the browser to collect information, respond to the browser and store user information in order to target developers work out a lot of tedious. The current ASP version offers a total of six built-in objects, the following examples we will study were carried out.
1, Request Object
You can use the Request object to access any HTTP requests based on passing all the information from HTML forms to use POST method or GET method of passing parameters, cookie, and word operations. Request object allows you to access the client sends the binary data to the server.
Request syntax:
Request [. Collection | property | method] (variable)
Here will select a number of commonly used object syntax analysis
1, Form
Form collection form by using the POST method HTTP request sent to retrieve the body of the email form element value.
Grammar
Request.Form (element) [(index) |. Count]
Parameter
element specifies a collection of elements to retrieve the name of the table.
index optional parameters, use this parameter can be accessed over the value of a parameter in a. It can be 1 to Request.Form (parameter). Count any integer between.
Count the number of elements in the collection
Form a collection of parameters in the body by the name of the request to the index. Request.Form (element) the value of the request body of an array of all element values. By calling Request.Form (element). Count to determine the number of parameter values. If the parameter is not associated multiple values, then the count is 1. If you can not find the argument, count to 0. There are multiple values to reference the form element in a single value, you must specify the index value. index parameter can be from 1 to Request.Form (element). Count of any number. If you reference a number of form parameters, without the specified index value, the returned data is a comma-separated string.
You can use repeat symbol to display the form on the request all the data values. For example, users fill out the form by specifying the number of values, see below.
Parameters for the hobby, you can use the following script retrieves these values.
<Html>
<Head> <title> </ title> </ head> <body>
<P> Please fill in your love </ p>
<Form method = “POST” action = “form.asp”>
<P> <input type = “text” name = “hobby” size = “20″> <br>
<Input type = “checkbox” name = “hobby” value = “Soccer”> football <input type = “checkbox” name = “hobby” value = “Table”> tennis </ p>
<P> <input type = “submit” value = “send” name = “B1″> <input type = “reset” value = “re-fill” name = “B2″> </ p>
</ Form>
<% For Each i In Request.Form (“hobby”) Response.Write i & “<BR>” Next%>
</ Body> </ html>
Cut and paste the code above into Notepad book (note the “<” followed by a space removed), save for the form.asp file and run, request object can you fill in the form or choose the different elements of the content will be element-by- displayed.
Of course, using the For … Next loop can generate the same output, as follows:
<%
For i = 1 To Request.Form (“hobby”). Count <
Response.Write Request.Form (“hobby”) (i) & “<BR>” Next <
%>
2, QueryString
QueryString collection retrieves HTTP query string variables, HTTP query string by a question mark (?) After the value specified. Such as:
<A HREF = “example.asp? String = this is a sample”> string sample </ A>
Generate a value of “this is a sample” of the variable name string. Form, or by the user by sending in their browser’s address box, type the query can generate the query string.
Grammar
Request.QueryString (variable) [(index) |. Count]
QueryString collection allows you to retrieve the QUERY_STRING variable name. Request.QueryString (parameter) value is there in all the parameters in the QUERY_STRING value of the array. By calling Request.QueryString (parameter). Count the number of parameters determine the value.
We can also use the QueryString to achieve with the same functionality as the previous example. Only need to replace request.form part as follows:
<%
For Each i In Request.querystring (“hobby”)
Response.Write i & “<BR>”
Next
%>
3, Cookies
What is a Cookie? Cookie is a label, when you visit a need to uniquely identify your site to the WEB site, it will be on your left a mark on the hard disk, the next time you visit the same site, site page will look the mark. Each has its own WEB site marker, tag content can be read at any time, but can only be completed by the site’s pages. Each site’s Cookie Cookie with all the other sites in the same folder in different file time (your Windows directory in the Cookie folder to find them). A Cookie is a unique customer identification tags, Cookie can be included in a dialogue or a few of the dialogue between a WEB site on all pages to share information, use the Cookie can also exchange information between pages. Request Cookies provided by a collection allows users to retrieve the HTTP request sent in the cookie value. This feature is often used in client requests authentication password, and electronic bulletin boards, WEB chat rooms ASP program.
Grammar
Request.Cookies (cookie) [(key) |. Attribute]
Parameter
cookie to retrieve the value specified cookie.
optional parameter key for the dictionary from the cookie to retrieve the value of sub-keywords.
attribe specified information about the cookie itself. Such as: HasKeys read-only, specify whether the cookie contains the keyword.
Can contain a key value to access the cookie dictionary sub-keywords. If you visit cookie dictionary is not specified key, then all the keywords will be returned as a single query string. For example, if two keywords MyCookie, First and Second, which were not specified in the call Request.Cookies any one keyword, it will return the following string.
First = firstkeyvalue & Second = secondkeyvalue
If the client browser to send two of the same name cookie, which then Request.Cookie will return a path to deeper structures. For example, if there are two of the same name of the cookie, but one of the path attribute to / www / and the other is / www / home /, the client browser, while the two cookie is sent to the / www / home / directory , then Request.Cookie will only return the second cookie.
To determine if a cookie is not a dictionary cookie (cookie has had keywords), use the following script.
<% = Request.Cookies (“myCookie”). HasKeys%>
If myCookie is a cookie dictionary, the preceding assignment to TRUE. Otherwise, it is FALSE. Let us look at a cookie application example:
<%
nickname = request.form (“nick”) response.cookies (“nick”) = nickname
\ ‘With the response object to write the user name into Cookie
response.write “Welcome” & request.cookies (“nick”) & “to our small station!”
%>
<Html> <head> <meta http-equiv = “Content-Type” content = “text / html; charset = gb2312″>
<Title> cookie </ title>
<Meta name = “GENERATOR” content = “Microsoft FrontPage 3.0″> </ head>
<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 = “re-fill” name = “B2″> </ p> </ form>
</ Body> </ html>
This is a WEB-based BBS, or CHAT in the ASP program commonly used approach, it will fill the surface of the user start page stored in the cookie name, so that the procedures followed can easily call on the user’s nick the.
4, ServerVariables
We all know that website in the browser when using the transport protocol is HTTP, the HTTP record the title of the document will be of some client information, such as: customer’s IP address, etc., and sometimes requires server-side information according to different client make a different reflection on the need to use this time to obtain needed information ServerVariables collection.
Grammar
Request.ServerVariables (server environment variable)
More because the server environment variables, the authors used only the number of variables in the following table:
ALL_HTTP client sends all the HTTP header file.
CONTENT_LENGTH clients send the content length.
CONTENT_TYPE content of data types. Example: “text / html”. Query with additional information for use with such HTTP query GET, POST and PUT.
LOCAL_ADDR return to accept the request of the server address. If you bind multiple IP addresses on multiple host machines to find the address used by the request, this variable is very important.
LOGON_USER Windows NT user login account.
QUERY_STRING HTTP request query question mark (?) After information.
REMOTE_ADDR request of the remote host (client) of the IP address.
REMOTE_HOST request of the host (client) name. If the server is no such information, it is set to empty MOTE_ADDR variable.
REQUEST_METHOD The method used for the request. Equivalent to HTTP’s GET, HEAD, POST, etc..
SERVER_NAME self-reference appears in the URL of server host name, DNS alias or IP address.
SERVER_PORT send the requested port number.
We can use the following script to print out all of the server environment variable.
<TABLE>
<TR> <TD> <B> Server Variable </ B> </ TD> <TD> <B> Value </ B> </ TD> </ TR> <% For Each name In Request.ServerVariables%>
<TR> <TD> <% = name%> </ TD> <TD> <% = Request.ServerVariables (name)%> </ TD> </ TR> </ TABLE>
<% Next%>
« ASP Tutorial: ASP script loop Next Post
ASP Basics Tutorial: ASP Built-in Application and Session objects »

