8.ASP built-in object response

xiaoxiao2021-03-06  41

In the previous author, I will introduce one of the REQUEST of the ASP built-in object to everyone. I believe that you can be skilled by a series of practices. This article will continue to introduce another built-in object of ASP. Recently, many friends come to "sisters" to urge the speed of the ASP article, and urgently ask where to ask about ASP. I am deeply driven by everyone's learning, I decided to take some ASP information information you usually collect and share it, I also hope that all friends can generously tell the author about the ASP information about ASP, thank you . Due to the current domestic teaching Chinese textbooks, the Chinese textbooks developed specifically for the ASP website are even unheard (may be the author's lonely), but recently heard a Tsinghua University Press publishing about MS Interdev's fool book. Among them, there are ASP teaching, and a Chinese manual of Active Server Page 2.0, so the author is currently related to the information and information of ASP through foreign websites, which is the main reason for the author writes this paper. Below I will list some of the more classic ASP sites in Bookmark:

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

This is the author's visit the most frequent ASP website. It is also one of the world's largest and most comprehensive websites. It not only has the latest ASP literature, free components, and a complete ASP introductory textbook, it is ASP The center of the website, through it you can reach countless ASP-related sites.

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

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

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

This is the most online ASP exchange site you see. It has an ASP's answer, ASP mail list information, ASP skills, you may need a few months to read this information. And at http://www.15seconds.com/allcomponents.asp You can read the latest ActiveX components and a large number of free components, and attach a very practical documentation and example.

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

Everyone knows that Active Server Page is a set of NT IIS-based web server-side environments proposed by Microsoft. Then this ASP technical description site built by Microsoft's own yourself, everyone is of course not seen.

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

Here you can get countless practical ActiveX components, and download their trial version, but most of them are most important components.

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

Do you still remember the Browser Capabilitie component that the author is used in the ASP2 article? At this site you can get the latest browscap.ini file, it has information on the browser provided by Microsoft, so that you can judge that the customer browser in the ASP is not lost.

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

The most powerful and convenient function of ASP is the connection with the database. Through the ACTIVEX component built by ASP, we can easily connect the web with all the ODBC compatible databases, you can get a lot of practical use on this Microsoft site. ADO data. 8, http://www.cobb.com/m_sbn4/

A nice ASP Forum, you can post your questions there, read the questions and answers from others.

Below, we started to learn another built-in object response in ASP.

In contrast to request is the client HTTP information, the Response object is used to control information sent to the user, including direct sending information to the browser, redirect the browser to another URL, or set the value of the cookie.

grammar

Response.collection | Property | Method

First, attribute

1, Buffer

The buffer property indicates whether the buffer page is output. When the buffer page is output, only all server scripts of the current page are handled or when the flush or end method is called, the server will send the response to the client browser, and the server will not set up the output to the client browser. Attributes. Therefore, the response.buffer should be called at the first line of .asp file.

2, Charset

The Charset property attached the character set name to the back of the Content-Type title in the Response object. For ASP pages that do not contain the response.charset attribute, the Content-Type title will be: Content-Type: Text / HTML.

We can specify the Content-Type title in the .asp file, such as:

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

The following results will be produced:

Content-type: text / html; charset = GB2312

Note that this feature is inserted into the Content-Type title regardless of whether the character set represented by the string is valid. And if a page contains multiple tags containing response.charset, each response.charset will replace the previous CharsetName. In this way, the character set will be set to the last instance of Response.Charset in this 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 it is expired on the browser buffered. If the user returns to this page before a page expires, the page in the buffer is displayed. If you set Response.expires = 0, the cached page can be expired immediately. This is a more practical attribute that when the customer enters the Web site through the ASP's login page, this property should be used to expire immediately to ensure security.

5, ExpiresAbsolute

Different ExpireSabsolute properties with Expires properties Specify the exact expiration date and time of the page cached in the browser. If the user returns to the page until the user is returned, the page in the cache is displayed. This home page expires on the same day if not specified. If the date is not specified, the home page expires at the specified time of the script running on the day. The following example specifies the page at 9:00 pm on December 10, 1998.

<% Response.expiresabsolute = # DEC 12, 1998 9: 00: 30 #%>

Second, the method

1, Clear

You can clear all HTML output in the buffer with the Clear method. However, the CLEAR method only clears the response body and does not clear the response title. You can use this method to handle error conditions. However, if the response.buffer is not set to True, the method will cause an error in runtime. 2, END

The End method causes the web server to stop processing scripts and returns current results. The remaining content in the file will not be processed. If the response.buffer is set to TRUE, calling Response.end will buffer output.

3, Flush

The Flush method immediately transmits the output in the buffer. If the response.buffer is not set to True, the method will result in a runtime error.

4, Redirect

The Redirect method enables the browser to immediately redirect the URL specified by the program. This is also a method we often use, so that the programmer can specify different pages for different customers according to the different customers, specify different pages according to different situations. Once the REDIRECT method is used any response text content that is explicitly set on the page will be ignored. However, this method does not send other HTTP titles set to the client, which will generate an automatic response body that will redirect URLs as a link. The Redirect method sends the following explicit title, 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 our usual ways, it is written to the current HTTP output in the specified string.

Third, collection

Response object has only one collection - Cookie

Cookies set Set the value of cookie. Create it if the specified cookie does not exist. If there is, set the new value and delete the old value.

grammar

Response.cookies (cookie) [(key) | .attribute] = VALUE

The cookie here is the name of the specified cookie. And if Key is specified, the cookie is a dictionary. Attribute specifies information about cookie itself. Attribute parameters can be one of the following:

If Domain is specified, the cookie will be sent to the request to the domain.

Expires Specifies the expiration date of the cookie. In order to store the cookie on the client disk after the session, you must set this date. If the settings of this attribute do not exceed the current date, the cookie will expire after the task is completed.

Haskeys Specifies whether cookies contains keywords.

If the PATH is specified, the cookie will only send only the request to the path. If this property is not set, the path to the application is used.

At this point, we have learned all attributes, methods, and collection of the response object, the author will give you a simple program, let everyone deepen understanding through practice. First clip the following programs into the Notepad and save as ASP7.ASP. (Note will remove the space between the

<%

DIM User

DIM FLAG

DIM PWD

DIM SAY

Response.buffer = true 'Turn on Buffet Function

Response.contentType = "text / html"

Response.charset = "GB2312"

User = Request.form ("UserName")

PWD = Request.form ("Password")

Say = Request.QueryString ("Say")

%>

Username:

The password:

<%

If Say = 1 THEN

Response.write "Welcome to the book!"

END IF

IF Say> 1 THEN

"Welcome to the ASP website" Welcome again! "

END IF

IF user = "adm" and pwd = "shusheng" then

Response.expires = 1 'Set this page to store 1 minute after the browser buffer.

Flag = 1

Elseif User = "Guest" and pwd = "guest" then

Response.expires = 0 'The cached page expires immediately.

Response.clear 'Clear the page stored in the cache

Flag = 2

Elseif User = "VIP" and PWD = "VIP" THEN

Response.write "Welcome VIP" ASP website "

Flag = 3

Else

Flag = 0

Response.end 'immediately stops script processing and outputs the page in the cache

END IF

Response.write "

%>

Dynamic website design Eight eight martial arts --ASP (7) Practice practice

The following procedure is saved as ASP7B.ASP.

<%

DIM Saysay = Request.QueryString ("Flag")

SELECT CASE SAY

Case "1"

Response.Redirect "Asp7.asp? Say = 1"

Case "2"

Resp6.Redirect "Asp7.asp? Say = 2"

Case "3"

Resp6.Redirect "Asp7.asp? Say = 3"

Case "0"

Response.Redirect "asp7.asp? Say = 0"

End SELECT

%>

Put these two programs in a Web virtual directory with permissions, and access ASP7.asp in HTTP. In both programs we fully utilize two ASP built-in 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 you to enter your username and password. If you enter your username: ADM, password: shusheng, the following page will appear:

Why is this? Because we set the page cache, when you use a guest login, the judgment program automatically clears all the pages stored in the cache, but only the results of the script execution are displayed.

Then why only only display a FORM dialog when logging in to the ASP7.asp page? Because the program determines that the user is not both the ADM, it is not GUEST and VIP, so executes response.end, immediately display the FORM stored in the cache, and stop all script processing, including the pure HTML code display.

Whether you use ADM or a guest or VIP to log in? You can see a chain, the supercharge point to file asp7b.asp, when we click on the chain, asp7.asp will send the value of the variable flag as a parameter. ASP7B.ASP, while the latter makes judgments based on the value of this parameter, and uses Response.Redirect to return ASP7.ASP based on different situations, and also sends a value of a variable SAY to ASP7.ASP. As a result, asp7.asp will do different reactions based on this parameter.

Everyone now saw two very simple programs, you can do a variety of different display results for the same page, this is the charm of the ASP, you can use this demonstration program based on this demonstration program. Some changes to master the two internal construction objects we have learned. Today's courses are here, I have to explain two things in the end. First, many friends to believe where you can see the first few articles of the ASP article, please click here to find it. Second, some friends reflect the ASP program in the text, which is mainly because chinabyte's page is generated by a database, which is limited to code with HTML or ASP format in the article, so adds to all


New Post(0)