ASP object structure

xiaoxiao2021-03-06  95

ASP object structure

As we have learned the basic application of ASP, now we have to understand the object structure of the ASP, then everyone can give an anti-three, do not need me to explain every example. This part may have some difficulties, but if you want to learn something, is it not afraid?

First, Request

The REQUEST object saves customer information in several collection for ASP applications. The general access method is:

Request.collection ("MEMBERNAME")

When you don't specify a collections, all collections are searched in (1) queryString, (2) form, (3) cookie and (4) ServerVariable, when discovers the first matching variable, it is considered that he is to reference the member of. Of course, in order to improve efficiency, you'd better explicitly specify the members in that collection.

QueryString collection

When the HTML form passes the data to the ASP file using the GET method, the data is saved in the collection queryString. Its members can have multiple values ​​associated with it, that is, in the same form, multiple elements can have the same name, the following generation

Code Access these data: <% for? Each? Item? In? Request.QueryString ("name")

Response.write? Item? & ""

NEXT?%>

Form Collection - When the form is single with a POST method, the data is saved in the Form collection.

ServerVariable Collection - Save information from the HTTP header with the HTTP request, you can get information about the browser, the main members are: remote_addr? Remote host IP address

Remote_host? Remote host name

Remote_user? Customer Name

Request_method? Request method (such as Post, Get, Head)

Server_name? Server name

Server_Protocol? Server version number (such as http / 1.0)

?

Second, Response object

The content used to control the HTML returned to the customer, there are several properties and methods. Here are what I think is important:

Buffer Properties - If true, the content of Response is to write to the buffer, and send it to the customer when the script is processed.

Status properties - the status of the HTTP? Response message. The status code returned by the server consists of three digits, which can be used to test phase and conversion control to other sites (ie Forward)

Write Method - Output HTML to customers, can be any legal HTML script.

Redirect Method - Enables the browser to realligate to another URL, such as:

<% browsetype = request.servervariables ("http_user_agent")

IF? Left (browsetype, 11) = "mozilla / 2.0"? THEN

Response.Redirect? "Fancystart.asp"

Else

Response.Redirect? "Oldstart.asp"

END? IF%>

CLEAR Method - If the buffer property is True, the CLEAR method knows all buffer content.

FLUSH Method - Send the buffer content to the customer.

End method - When Active? Server encounters this method, immediately stop processing ASP files, if there is buffer, send content to customers immediately.

BinaryWrite Method - Output binary data?

Third, the request object and the cookies collection of the response object

1. Write cookies - response.cookies ("Cookie Name) [(" key name "). Properties] = value. If the cookie already exists, the value is replaced by the new value, otherwise, the cookie is created. For example: <%? Response.cookies ("newcookie") = "new? Cookie? Value"?%>

2. Read cookies - such as: <% = Request.Cookies ("NewCookie")%> cookies also have some properties, see the information.

Fourth, Application object

Active? Server application is all files in virtual directory and its subdirectory, namely a web. You can share information in all users of the application object, and you can hold data during server running. He has some methods and events that control access to application layer data.

Application itself does not have built-in attributes, you can have a user-defined: Application ("Properties Name) = value

The data saved in the Application object can be read by all users of the Application. If you used to do your access:

Application ("Avisits") = Application ("Avisits") 1

There are two methods:

LOCK Method - When a user calls Lock, only the current user can edit or add the properties of the Application object.

UNLOCK method - Be sure to remember, call the LOCK, and must call UNLOCK when completing.

There are two events:

Application_onstart event: Call when the application starts.

Application_onstart event: Call when the application terminates.

Both events plus the handlers of the session of the two events in the file global.asp, one web application only

There is a global.asa file and placed under the root of the application. An example of a global.asp file is as follows:

SUB? Application_OnStart

DIM? Lachats (15)

Application ("gachats") = machats

Application ("Gicounter") = 0

END? SUB

Five, session object

Active? Server uses session to set up a single user who uses a single user who uses your application. When the user requests the URL of the ASP file in the Active? Server application, start the session. By default, if there is no user request, the server only retains the session for 20 minutes. Users can also change by setting session attribute Timeout. Or call the session.abandon method to release the session object.

SessionID Properties - Unique identifier identifies a session.

TimeOUt property - Defines the time limit for session reserved, in minutes, such as: session.timeout = 10

Like Application, Session can also be defined by the user. The only way of the session is Abandon to cancel the user's session object and release the server resources occupied by it. Such as: <% session.abandon%>

The event has session_onstart and session_onend, and its handler should be placed in the file Glabal.asa.

Sixth, Server object 1.htmlencode method: HTML encoding for a specific string, if you have the following content:

The? Underline? Tag ()? Is? Used? To? Underline? The? Surrounded? Text.

But it is likely to be actually displayed: the? Underline? Tag ()? Is? Used? To? Underline? The? Surrounded? Text.

To avoid this, you can call the HTMLENCODE method of the Server object, such as: <%

Response.Write? Server.htmlencode ("the? Underline? Tag ()? Is? Used? To? Underline?")%>

2.urlencode method

The string is encoded according to the URL rule. When the string data is passed to the server in a URL format, there is no space between the string, and there is no special character. At this time, you must use the URL encoding.

3.createObject method

Used to create an ActiveX component routine that has been registered to the server machine, this is probably the most important method :-)

The sentence is as follows: Server.createObject ("Componentname")

Components that can be started as routines can be all built-in components that ActiveX can use, actually any ActiveX component existing on the server. For example, to use financial calculations, the steps are as follows:

1. Create an object <% set? X = server.createObject ("extend.financial");%>

2. Method of calling the object <% set? X = server.createObject ("extend.financial")

Response.write? format (x.futval (.07 / 12, 200, -500), "###, ###, ## 0.00")%>

3. Release routine <% set? X = nothing%>

Seven, FileSystem and TextStream objects

FileSystem and TextStream objects can be used to establish access to file systems, and provide mechanisms for sequential access files. FileSystem does not have attributes, only two ways, the first method is the CreateTextFile method, you can create a new text file on the host and return the TextStream object to provide the access mechanism for the newly created file. The second is the OpenTextFile method to open text files for sequential access and return a TextStream object. Such as: <% set? Fsfilesys = creteObject ("scripting.filesystemobject")

Set? tscoffee = fsfilesys.createtextfile ("c: /coffe.txt", true)

TscoFee.writeline ("MAN, I? Could? Use? Some? coffee.")

Tscoffee.close%>

The usage of the TextStream object is:

ATENDOFLINE: Returns true if the file is at the end of the row

AtendOfScreen: Returns true if the current character is at the end of the file

Column: Returns the number of current characters

Line: Returns the line number of the current character

The method of the TextStream object is:

Close: Close and release the TextStream object

Read: Reads a given number in a file into a variable

Readall: Read the full content of the file into a variable

Readline: Read the contents of the line number to a variable SKIP: Skip the given number characters

Skipline: Skip to the top

Write: writing such as string

WriteLine: Writing a string to the end of the wrap

Writeblanklines: Write a space for the top number

转载请注明原文地址:https://www.9cbs.com/read-124472.html

New Post(0)