ASP Basic Tutorial: ASP built-in object response

Source: Internet
Author: User
Tags classic asp

In the previous article, the author gave you a detailed introduction of ASP built in one of the objects of the use of Request, I believe you through a series of practice has been able to master, this article will continue to introduce another ASP built object Response.

Recently, a lot of friends to "sister son" urged me to speed up the text of the ASP article speed, and eagerly asked where there is a textbook about ASP. I am deeply impressed by everyone's enthusiasm for learning, so decided to collect some of their own information from the ASP to share with you, but also hope that all the friends can be generous to collect their own information about the ASP to tell the author, thank you. Due to the current domestic ASP of Chinese textbooks are rare, and specifically for the ASP Web site development of Chinese textbooks are unheard of (may be the author ignorant), but recently heard a Tsinghua University Press published on the MS InterDev of The Idiot book, which has ASP teaching, and a Active Server Page 2.0 of the Chinese manual, so at present the author is mainly through the foreign web site to obtain the information and information of the ASP, which is the author's main reason for writing this article. Below, I will list some of the more classic ASP sites in the bookmark:

1, http://www.activeserverpage.com/

This is the most frequently visited ASP Web site, is also the world's largest and most full of ASP's Web site, which not only has the latest ASP literature, free components, there is a complete ASP primer, it is the hub site of the ASP site, through which you can reach countless ASP related sites.

2, http://www.asphole.com/

This is a site for ASP vulnerabilities, but it is undoubtedly a complete ASP information site, not only provides an ASP article, and components also provide a detailed and thorough connection address.

3, Http://www.15seconds.com/faq and Http://www.15seconds.com/search

This is the largest online ASP communication site that the author sees, it has ASP troubleshoot answer, ASP mailing list information, ASP skill, you may need a few months time to read this information. In http://www.15seconds.com/AllComponents.asp you can read more about the latest ActiveX components and a lot of free components, along with very useful documentation and examples.

4, http://www.microsoft.com/workshop/server/asp/aspfeat.asp

We all know that the Active server Page is Microsoft proposed a set of NT IIS-based WEB server-side environment, then the Microsoft Self-built ASP technology description site, we certainly have to see.

5, http://www.serverobjects.com/

Here you can get countless useful ActiveX components and download their trial version, but unfortunately most of the excellent components are for money.

6, http://www.cyscape.com/asp/browscap/

Do you remember the Browser Capabilitie component that was used to identify the version of the client browser that the author described in the ASP2 article? At this site you can get the latest browscap. INI file, which has information about browsers not provided by Microsoft at each ASP installation, so that you can judge the customer's browser in ASP to be foolproof.

7, http://www.microsoft.com/data/ado/

ASP is the most powerful and convenient function of the connection with the database, through the ASP built-in ActiveX components, we can easily connect the WEB with all ODBC-compatible databases, on this Microsoft site you can get a lot of practical ADO data.

8, http://www.cobb.com/m_sbn4/

A good ASP forum where you can post your questions, read other people's Questions and answers.

Below, we begin to learn another built-in object Response ASP.

In contrast to request is to obtain client HTTP information, the Response object is used to control the information sent to the user, including sending information directly to the browser, redirecting the browser to another URL, or setting the value of the cookie.

Grammar

Response.collection|property|method

First, the attribute

1. Buffer

The Buffer property indicates whether the page output is buffered. When a buffered page is output, only the server script for the current page has finished processing or the Flush or End method is called, the server sends the response to the client browser, and the server will not be able to set the buffer property after it is sent to the client browser. Therefore, you should call Response.Buffer on the first line of the. asp file.

2, Charset

The Charset property attaches the character set name to the Response object after the Content-type title. For ASP pages that do not contain the Response.Charset property, the Content-type title will be: content-type:text/html.

We can specify content-type headings in the. asp file, such as:

<% response.charset= "gb2312")%>

The following results will be produced:

content-type:text/html; charset=gb2312

Note that the feature inserts a string in the Content-type header, regardless of whether the character set it represents is valid. And if a page contains multiple tags that contain response.charset, each Response.Charset replaces the previous charsetname. In this way, the charset is set to the value specified by the last instance of Response.Charset in the page.

3, ContentType

The ContentType property specifies the HTTP content type of the server response. If ContentType is not specified, the default is text/html.

4, Expires

The Expires property specifies how long it will be before the page that is cached on the browser expires. If a user returns to this page before a page expires, the page in the buffer is displayed. If you set response.expires=0, you can make cached pages expire immediately. This is a more practical property, when the customer through the ASP landing page into the WEB site, should use this property to make the landing page immediately expire, to ensure security.

5, ExpiresAbsolute

Unlike the Expires property, the ExpiresAbsolute property specifies the exact expiration date and time of the page that is cached in the browser. If the user returns to the page before it expires, the page in the cache is displayed. If no time is specified, the home page expires at midnight on that day. If no date is specified, the master page expires at the specified time of the day the script runs. The following example specifies that the page expires on December 10, 1998 9:00 minutes and 30 seconds.

<% response.expiresabsolute= #Dec 12,1998 9:00:30#%>

Second, the method

1. Clear

You can clear all the HTML output in the buffer by using the clear method. The clear method only clears the response body and does not clear the response header. You can use this method to handle error conditions. However, if Response.Buffer is not set to TRUE, the method causes a run-time error.

2. End

The end method causes the WEB server to stop processing the script and return the current results. The remaining content in the file will not be processed. If Response.Buffer is set to TRUE, calling Response.End will buffer the output.

3. Flush

The Flush method immediately sends the output in the buffer. If Response.Buffer is not set to TRUE, the method causes a run-time error.

4, Redirect

The Redirect method immediately redirects the browser to the URL specified by the program. This is also a method we often use, so that programmers can according to the different responses of customers, different customers to specify different pages or according to different circumstances to specify a different page. Once the Redirect method is used, any response body content that is explicitly set in the page is ignored. However, this method does not send the other HTTP headers set by the page to the client, resulting in an automatic response body that contains the redirect URL as a link. The Redirect method sends the following explicit caption, where the URL is the value passed to the method. Such as:

<% Response.Redirect ("www.chinabyte.com")%>

5. Write

The Write method is one of the most commonly used methods in our usual way, which is to write the specified string to the current HTTP output.

Three, the collection

The Response object has only one collection--cookie

Cookies set the value of the cookie. If the specified cookie does not exist, it is created. If present, set a new value and delete the old value.

Grammar

Response.Cookies (cookie) [(key) |. Attribute]=value

The cookie here is the name of the specified cookie. If you specify a key, the cookie is a dictionary. attribute specifies information about the cookie itself. The attribute parameter can be one of the following:

If domain is specified, the cookie is sent to the request for that domain. {Shanghai Cheng Kai Men's Hospital: http://www.edzl.cn/Finishing}

EXPIRES Specifies the expiration date of the cookie. The date must be set to store the cookie on the client disk after the session ends. If the setting for this property does not exceed the current date, the cookie expires after the task ends.

HasKeys Specifies whether the cookie contains keywords.

If path is specified, the cookie is sent only to requests for that path. If this property is not set, the application's path is used.

At this point, we have learned the theoretical knowledge of all the properties, methods and collections of the Response object, the following author will show you a simple program, through practice to deepen understanding. First, paste the following program into your Notepad and save it as asp7.asp. (Note that the space between < and% is removed!!!)

<%
Dim User
Dim Flag
Dim pwd
Dim say
Response.buffer=true \\\ ' Enable buffering page function
Response.contenttype= "Text/html"
response.charset= "gb2312"
User=request.form ("username")
Pwd=request.form ("password")
Say=request.querystring ("Say")
%>
< form method= "POST" action= "asp7.asp" >
< p> user name:< input type= "text" name= "username" size= "Nine" >< br>
Password:< input type= "password" name= "password" size= ">< br>"
< input type= "submit" value= "commit" Name= "B1" >< input type= "reset" value= "Cancel" name= "B2" ></p></form >
<%
If Say=1 Then
Response.Write "Welcome scholar to visit!"
End If
If say >1 Then
Response.Write "Welcome to the scholar's ASP website again!"
End If
If user= "ADM" and pwd= "Shusheng" Then
Response.expires=1 \\\ ' Sets the page to expire after 1 minutes of storage in the browser's buffer.
Flag=1
ElseIf user= "Guest" and pwd= "guest" then
Response.expires=0 \\\ ' causes cached pages to expire immediately.
Response.Clear \\\ ' empties the pages stored in the cache
flag=2
ElseIf user= "VIP" and pwd= "VIP" Then
Response.Write "Welcome VIP Visit Scholar's ASP website"
Flag=3
Else
Flag=0
Response.End \\\ ' Stop the script processing immediately and output the page in the cache
End If
Response.Write "< p>< a href=\\\ ' asp7b.asp?flag=" &flag& "\\\" > Dynamic Web Design terrorize--asp (7) Practical exercises </A ></p> "
\\\ ' sends the value of the variable flag to asp7b.asp
%>
< p> dynamic website design terrorize--asp (7) Practical Exercises </p>
Then save the following program as Asp7b.asp.
<%
Dim saysay=request.querystring ("flag")
Select case say
Case "1"
Response.Redirect "Asp7.asp?say=1"
Case "2"
Response.Redirect "asp7.asp?say=2"
Case "3"
Response.Redirect "Asp7.asp?say=3"
Case "0"
Response.Redirect "Asp7.asp?say=0"
End Select
%>

Place the two programs under the WEB virtual directory with Execute permissions and access the asp7.asp in HTTP mode. In both of these programs we have fully utilized the two ASP built-in objects we have learned so far: Request and Response. When you first access the asp7.asp file, a Form appears on the page and prompts for a user name and password, if you enter the username: ADM, Password: Shusheng, the following page appears:


If you enter the user name: Guest, Password: Guest, only the following page appears:


What is this for? Because we set the page cache, when using guest login, the judgment program automatically empties all of the pages that were stored in the cache before displaying the results of the script execution.

So why did you just display a Form dialog box when you first landed on the asp7.asp page? Because the program now determines that the user is neither ADM nor guest nor VIP, executing response.end immediately displays the Form stored in the cache and stops all subsequent script processing, including the display of plain HTML code.

Whether you are using ADM or guest or VIP landing on the page you can see a hyperlink, the hyperlink to the file asp7b.asp, when we click the hyperlink, asp7.asp the value of the variable flag as a parameter to asp7b.asp, and the latter according to the value of the parameter to make Judge, and use Response.Redirect according to different circumstances, and then forcibly return asp7.asp, and also the value of a variable say as a parameter sent to asp7.asp. As a result, asp7.asp will react differently based on this parameter.

We all see now we just use two very simple programs, you can do to the same page a variety of different display results, this is the charm of the ASP, you can use this demonstration program as the basis, to make some changes to master the two built-in objects we learn.

ASP Basic Tutorial: ASP built-in object response

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.