Lesson eighth: ASP Built-in object response

Source: Internet
Author: User
Tags date character set contains continue flush header variable access
In the previous article, the author gave you a detailed introduction of the ASP built-in object one of the use of Request, I believe that you through a series of practice has been able to master, this article will continue to introduce an ASP's another built-in object Response.

Recently, a lot of friends to "sister son" urged me to speed up the article a SP writing speed, and eagerly asked where there is a SP's textbook. I was deeply affected by the enthusiasm of the study, so I decided to collect some of the SP information information to share with you, but also hope that all the friends can generously collect their own information about A SP to tell the author, thank you. As a result of the current Chinese textbooks on SP A are rare, and the Chinese textbook specially developed for a SP website is unheard of (may be the author's ignorance), but recently heard a book published by Tsinghua University Press about M S InterDev, which has a SP's teaching, and a ctive Server Page 2.0 Chinese Manual, so at present, the author is mainly through the foreign web site to obtain the information and information of SP A, which is the author of the main reason for writing this article. Below I will list some of the more classic a SP sites in B Ookmark:

1,http://www.activeserverpage.com/ This is the author visit the most frequent ASP site, is also the world's largest and most complete one of the ASP's Web site, it has not only the latest ASP literature, free components, there is a complete a SP Primer, which is the central site of the ASP site, through which you can reach countless ASP-related sites.

2,http://www.asphole.com/ This is a vulnerability for the ASP site, but it is undoubtedly a complete ASP information site, which not only provided the ASP articles, and components also provide a thorough and exhaustive connection address.

3,Http://www.15seconds.com/faq and http://www.15seconds.com/search This is an author to see the largest online ASP Exchange site, it has ASP Resolving's answer, ASP mailing list information, ASP tips, you may need a few months to read this information. In http://www.15seconds.com/AllComponents.asp you can read the latest ActiveX components and a lot of free components in detail, with very useful documentation and examples.

4,http://www.microsoft.com/workshop/server/asp/aspfeat.asp Everyone knows that the Active server Page is a Microsoft proposed WEB service based on NT IIS Device-side environment, then this is built by Microsoft's own ASP Technical 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 money.

6.http://www.cyscape.com/asp/browscap/ Do you remember the Browser Capabilitie component that the author described in ASP2 to identify the client browser version? At this site you can get the latest browscap. INI file, it has every ASP installation when Microsoft did not provide the browser information, so you in the ASP to judge the client browser can be foolproof.

7,http://www.microsoft.com/data/ado/ ASP the most powerful and convenient functionality than the connection with the database, through the ASP built-in ActiveX components, we can easily the WEB with all and ODBC compatible Database, you can get a lot of practical ADO data on this Microsoft site.

8,http://www.cobb.com/m_sbn4/ a good ASP forum, where you can paste your questions, read other people's Questions and answers. Below, we begin to learn another ASP's Response object.

Instead of obtaining client HTTP information, the Response object is used to control the information sent to the user, including sending the message directly to the browser, redirecting the browser to another URL, or setting the value of the cookie.

   Grammar Response.collection|property|method

   One, property

1, Buffer buffer property indicates whether to buffer page output. When the page output is buffered, the server sends the response to the client browser only after all server scripts for the current page have been processed or the Flush or End method is invoked, and the server will no longer be able to set the buffer property after it has been sent to the client browser. You should therefore call Response.Buffer on the first line of the. asp file.

2. The Charset Charset property attaches the character set name to the back of the Content-type header in the Response object. 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 headers in the. asp file, such as:

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

The following results are produced:

content-type:text/html; charset=gb2312

Note that the feature inserts it into the Content-type header, regardless of whether the character set represented by the string is valid. And if a page contains more than one tag that contains Response.Charset, each Response.Charset replaces the previous charsetname. In this way, the character set is set to the value specified by the last instance of Response.Charset in the page.

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

4. The Expires Expires property specifies how long it will be before the page that is cached on the browser is expired. 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's Landing page into the Web site, you should use this property to make the landing page expire immediately to ensure security.

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

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

   Second, the method

1. Clear clears all HTML output in the buffer with the clean method. However, the clear method clears only 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, this method will cause a run-time error.

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

3. The Flush 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. The Redirect Redirect method causes the browser to immediately redirect to the URL specified by the program. This is also a method that we often use so that programmers can specify different pages for different customers depending on the customer's response, or different pages for different situations. 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 client a different HTTP header for the page set, resulting in an automatic response body containing the redirected 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. The write write method is one of the most common methods we usually use to write the specified string to the current HTTP output.

   third, the collection The Response object has only one collection--cookie

Cookies collection sets the value of the cookie. If the specified cookie does not exist, it is created. If it exists, the new value is set and the old value is deleted.

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

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

If domain is specified, the cookie is sent to the request in the domain.

EXPIRES Specifies the expiration date for the cookie. To store cookies on the client disk after the session has ended, you must set the date. 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 the request for that path. If this property is not set, the path to the application is used.

So far, we have learned the theoretical knowledge of all the properties, methods, and sets of R Esponse objects, and the following authors will show you a simple procedure to deepen your understanding through practice. First clip the following program into a notepad and save it as a sp7.asp. (Note that the space between < and% is removed!!!)
<%
Dim User
Dim Flag
Dim pwd
Dim say
Response.buffer=true ' Turn on 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> username:< input type= "text" name= "username" size= "a" >< br>
Password:< input type= "password" name= "password" size= ">< br>"
< input type= "submit" value= "submitted" 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 visit the Scholar's ASP website!"
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 the VIP visit Scholar's ASP website"
Flag=3
Else
Flag=0
Response.End ' stops script processing immediately and prints the page in the cache
End If
Response.Write "< p>< a href= ' asp7b.asp?flag=" &flag& "> Dynamic website Design Skills--asp Chapter (7) Practice Practice </a></ P> "
' Pass the value of the variable flag to asp7b.asp
%>
< p> dynamic Website design Skills--asp (7) Practice Practice </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 a WEB virtual directory with Execute permissions and Access asp7.asp in HTTP. In both programs we have fully utilized the two ASP-built objects that have been learned so far: Request and Response. When you first access the asp7.asp file, a Form appears on the page and prompts for the username and password, and if you enter the username: ADM, Password: Shusheng, the following page will appear:

If you enter the username: Guest, password: Guest, only the following page appears:

What is this for? Because we set up the page cache, when we log in using the guest, the judge automatically clears all the pages stored in the cache before the results of the subsequent script execution are displayed.

So why did you just display a Form dialog when you first landed on the asp7.asp page? Because at this point the program determines that the user is neither ADM nor guest and VIP, executes Response.End, immediately displays the Form stored in the cache, and stops all subsequent script processing, including the display of pure HTML code.

Whether you are using a DM or G uest or v IP landing on the page you can see a hyperlink, the hyperlink to file a sp7b.asp, when we click on the hyperlink, a sp7.asp the variable f lag value as an argument to a sp7b.asp, The latter is based on the value of the parameter to make judgments, and according to different situations using Response.Redirect and then forcibly return a sp7.asp, and also a variable s ay value as an argument sent to a sp7.asp. In this way, a sp7.asp will respond differently based on this parameter.

As you can see now, we've only used two very simple programs, can do on the same page a variety of different display results, this is the charm of the ASP, you can use this model program as a basis for some changes to master the two built-in objects we learned. Today's lesson is over, and at the end I have two things to say. First, a lot of friends to ask where you can see the ASP article of the previous articles, please click here you can find. Second, some friends reflect the text of the ASP program can not run, this is mainly because Chinabyte pages are generated by the database, it is limited to the article can not use HTML or ASP format code, so after all < symbols are added a space, you can only remove the < after the space You can run the program, remember. Next we will continue to learn another ASP built-in objects, please pay attention.



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.