Eighth article ASP Built-in object

Source: Internet
Author: User
Tags date character set contains continue flush header variable domain
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 ASP article writing speed, and eagerly asked where there is the textbook on ASP. I was deeply touched by the enthusiasm of everyone's study, so decided to collect some of their usual ASP information and share, but also hope that all the friends can generously collect their own information about the ASP to tell the author, thank you. As the current domestic Chinese textbooks on ASP are rare, and specifically for ASP Web site development of Chinese textbooks are unheard of (may be the author of Ignorance), but recently heard a book published by Tsinghua University on MS InterDev Fool book, which has the teaching of ASP, and a Active Server Page 2.0 Chinese Manual, so at present the author still mainly through the foreign website to obtain the ASP information and the material, this is also the author writes this article The main reason. 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 site by the author, is also the world's largest and most comprehensive web site on ASP, which not only has the latest ASP literature, free components, there is a complete ASP introductory materials, it is the central site of 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, which not only provides ASP articles, and components also provide a thorough and exhaustive join 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 answer, ASP mailing list information, ASP skills, 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

We all know that the Active server Page is a set of Windows NT IIS based WEB server environment, so the Microsoft set up its own ASP technical description site, we certainly have to see.

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

Here you can get a myriad of useful ActiveX components and download their beta versions, but unfortunately most of these excellent components are money.

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

Do you remember the Browser Capabilitie component that was introduced by the author 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/

The most powerful and convenient feature of ASP is the connection with the database, through the ActiveX components built in ASP, we can easily connect the WEB with all ODBC-compatible databases, 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 post your questions and 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

The Buffer property indicates whether the page output is buffered. 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, Charset

The 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, 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 much time is available to cache the paged memory on the browser. 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

Unlike the Expires property, the 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

You can clear all of the 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.

2, End

The 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, 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 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, Write

The 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.

Grammar

Response.Cookies (cookie) [(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.

Now that we have learned the theoretical knowledge of all the attributes, methods, and sets of the Response object, the following authors will show you a simple procedure that you can use to deepen your understanding. First clip the following program into a notepad and save it as a asp7.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 article (7) Practice Practice </a>& L /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:

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 log on to the page with ADM or guest or VIP, you can see a hyperlink that points to the file asp7b.asp, and when we click the hyperlink, Asp7.asp sends the value of the variable flag as an argument to the asp7b.asp, which is based on the value of the parameter. Judge, and use Response.Redirect to forcibly return asp7.asp according to different situations, and also send the value of a variable say as an argument to asp7.asp. In this way, asp7.asp will react differently according to 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.