Object structure of ASP

Source: Internet
Author: User
Tags format extend html form http request variable time limit access root directory
Object
Now we have to systematically understand the object structure of the ASP, then, you can extrapolate, do not need me to explain each example too much. This part may be a bit difficult.

   First, Request
The Request object stores customer information in several collections for use in ASP applications. Common access methods are: Request.collection ("MemberName")
When you do not specify a collection name, use (1) QueryString, (2) Form, (3) cookie and (4) servervariable
In order to search all collections, and when the first matching variable is found, it is assumed that he is the member to be referenced. Of course, in order to improve efficiency, you'd better explicitly specify the members of that collection.
   QueryString Collection
When an HTML form uses the Get method to pass data to an ASP file, the data is saved in the collection querystring. Its members can have multiple values associated with it, that is, multiple elements in the same form can have the same name, and the following code accesses the data:
<%for each item in Request.QueryString ("Name")
Response.Write Item & "<br>"
Next%>
   Form Collection
When the table is in the Post method alone, the data is saved in the form collection.
   servervariable Collection
The message that the HTTP header is sent along with the HTTP request is saved, and you can get information about the browser through him, and the main members are:
REMOTE_ADDR Remote Host IP address
Remote_host Remote Host Name
Remote_user Customer Name
Request_method request method (e.g. Post,get,head)
Server_Name server name
Server_protocol Server version number, such as HTTP/1. 0)

   second, the response object
A number of properties and methods are used to control the content of the HTML returned to the customer. Here's what I think is important:
   Buffer Property
If true, the response content is written to the buffer and sent to the customer when the script is processed.
Status Property
Passes the state of the HTTP response message. The status code returned by the server is composed of three digits, which can be used for the test phase and transformation control to other sites (i.e. forward)
   Write Method
Export HTML to the customer, which can be any legitimate HTML script.
   Redirect Method
redirect the browser to a different 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 you set the Buffer property to True, the clear method clearly knows all the buffer contents.
   Flush Method
Send the buffered content to the customer immediately.
   End Method
When Active server encounters this method, it immediately stops processing the ASP file and, if there is a buffer, sends the content to the customer immediately.
   BinaryWrite Method
Output binary data

   third, the request object and the response object's Cookies collection
   1. Write Cookies
Response.Cookies ("cookie Name") [("Key Name"). Property]= Value
If the cookie already exists, the value is replaced with 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.

   Iv. Application Objects
An Active server application is a web of all files under a virtual directory and its subdirectories. You can use the Application object to share information among all users of the application software, and you can persist the data during server runs. He has some methods and events that control access to application-tier data.
Application itself has no built-in properties and can have user-defined: Application ("property name") = value
Data saved in the Application object can be read by all users of the application. If used to do access count: Application ("Avisits") =application ("Avisits") +1
There are two methods:
Lock:
When the user invokes lock, only the current user can edit or increase the properties of the Application object.
Unlock:
Be sure to remember that the lock is invoked and you must call unlock when you are done.
There are also two events:
Application_OnStart event: Called when the application starts.
Application_OnStart event: Called when the application terminates.
These two events, plus the handlers for the session's two events, are placed in the file global.asp, and a Web application has only one Global.asa file, and it is placed in the root directory of the application. An example of a global.asp file is as follows:
<script language= "VBScript" runat= "Server" >
Sub Application_OnStart
Dim Lachats (15)
Application ("Gachats") =machats
Application ("Gicounter") =0
End Sub

   v. Session Object
Active server uses session settings to persist data for a single user who uses the application. The session is started when the user requests the URL of an ASP file in an Active Server application. By default, the server retains only Session20 minutes if no user requests. Users can also change by setting the session's properties timeout. Or, the Session.Abandon method is called to release the Session object.
   SessionID Property
An identifier that uniquely identifies a session.
   Timeout Property
Define the time limit for session retention, in minutes, such as session.timeout=10
Like application, sessions can also be defined by the user.
The only way to session is abandon, which cancels the user's session object and frees up the server resources it occupies. such as:<%session.abandon%>
Events have Session_OnStart and Session_OnEnd, and their handlers should be placed in file Glabal.asa.

   six, server objects
   1.HTMLEncode Method
HTML-encodes a particular string, as you would have wanted to display the following:
The underline tag (<u></u>) is used to underline the surrounded text.
But it is likely to actually show:
The underline tag () is used to underline the surrounded text.
To avoid this situation, you can call the HTMLEncode method of the server object, such as:
<%
Response.Write Server.HTMLEncode ("The Underline tag (<U></U>) is used to underline the surrounded text.")
%>
   2.URLEncode Method
Strings are encoded according to the URL rules. When the string data is passed to the server in the URL format, there must be no spaces between the strings, no special characters, and then you have to encode the URL.
   3.CreateObject Method
Used to create an ActiveX component routine that has been registered to the server machine, which is probably the most important method:
The syntax is as follows:
Server.CreateObject ("ComponentName")
Components that can be started as routines can be all of the built-in components that ActiveX can use, actually any ActiveX components that exist on the server. For example, to use financial calculations, the steps are as follows:
1. Creating objects
<%
Set X=server.createobject ("extend.financial");
%>
2. Methods of calling Objects
<%
Set X=server.createobject ("Extend.financial")
Response.Write Format (X.futval (. 07/12,200,-500), "###,###,# #0.00")
%>
3. Release routines
<%
Set x=nothing
%>

   vii. filesystem and TextStream objects
FileSystem and TextStream objects can be used to establish access to file systems and provide a mechanism for sequential access to files. FileSystem has no properties, only two methods, the first method is the CreateTextFile method, you can create a new text file on the host, and return the TextStream object to provide access to the newly created file. The second is the OpenTextFile method, which opens a text file for sequential access and returns a TextStream object. Such as:
<%
Set Fsfilesys=createobject ("Scripting.FileSystemObject")
Set Tscoffee=fsfilesys.createtextfile ("C:\coffe.txt", True)
Tscoffee.writeline ("Man,i could use some coffee.")
Tscoffee.close
%>
   TextStream ObjectsUse of:
AtEndOfLine: Returns True if the current character of the file is at the end of the line
Atendofscreen: Returns True if the current character is at the end of the file
Column: Returns the number of the current character
Line: Returns the row number of the current character
   the method for TextStream objects is:
Close: Closes and releases the TextStream object
READ: Reads a given number of characters from a file into a variable
ReadAll: Read all the contents of the file into a variable
ReadLine: Reads the contents of a given line number into a variable
Skip: Skip a given number of characters
SkipLine: Skip to the top of the running script
Write: Writing as a string
WriteLine: Writes a string ending with a newline
WriteBlankLines: Write to top number of spaces


Related Article

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.