This article mainly introduces the relevant information about the ASP built-in object Response. Friends who need it can refer to it.
Next, we start to learn another built-in object of ASP, Response.
In contrast to Request that obtains client HTTP information, the Response object is used to control the information sent to the user, including sending the information directly to the browser, redirecting the browser to another URL, or setting the value of the cookie.
Syntax: Response.collection|property|method
1. Attributes
1. Buffer
The Buffer property indicates whether to buffer page output. When the buffered page output is output, the server will send the response to the client browser only after all server scripts on the current page have been processed or the Flush or End method is called. After the server sends the output to the client browser, the Buffer can no longer be set after the server sends the output to the client browser. property. Therefore, Response.Buffer should be called on the first line of the .asp file.
2. Charset
The Charset property appends the character set name to the aftermath of the content-type title 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 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 function inserts the character set represented by the string into the content-type header regardless of whether it is valid or not. 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 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 the buffered pages on the browser have expired. If the user returns to a page before it expires, the page in the buffer will be displayed. If response.expires=0 is set, the cached page can be expired immediately. This is a more practical property. When a customer enters the WEB site through the ASP's login page, he should use this property to make the login page expire immediately to ensure security.
5. ExpiresAbsolute
Different from the Expires property The ExpiresAbsolute property specifies the exact expiration date and time of the page cached in the browser. Before expiration, if the user returns to the page, the cached page will be displayed. If no time is specified, the homepage expires at midnight on the same day. If no date is specified, the home page expires at the specified time on the day the script is running. The following example specifies that the page expires at 9:00:30 am on December 10, 1998.
< % Response.ExpiresAbsolute=#Dec 12,1998 9:00:30# %>
2. Method
1. Clear
All HTML output in the buffer can be cleared using the Clear method. However, the Clear method only clears the response body and does not clear the response title. This method can be used to deal with errors. But if Response.Buffer is not set to TRUE, the method will cause a runtime 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 Response.Buffer is set to TRUE, calling Response.End will buffer the output.
3. Flush
The Flush method sends the output in the buffer immediately. If Response.Buffer is not set to TRUE, this method will cause a runtime error.
4. Redirect
The Redirect method causes the browser to immediately redirect to the URL specified by the program. This is also a method we often use, so that programmers can specify different pages for different customers or different pages according to different situations according to different responses. Once the Redirect method is used, any response body content that is explicitly set in the page will be ignored. However, this method does not send other HTTP titles set to the client for the page, resulting in an automatic response body that will redirect the URL as the link. The Redirect method sends the following explicit title, where the URL is the value passed to the method. like:
< % Response.redirect(www.jb51.com) %>
5. Write
The Write method is one of the most commonly used methods we usually use. It is to write the specified string to the current HTTP output.
3. Collection
Response objects have only one set -- Cookie
Cookies Collection Sets the value of the cookie. If the specified cookie does not exist, create it. If present, 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 a key is specified, the cookie is a dictionary. attribute Specifies the information about the cookie itself. The attribute parameter can be one of the following:
If Domain is specified, the cookie will be sent to the request for the domain.
Expires Specifies the expiration date for the cookie. In order to store cookies on client disk after the session ends, this date must be set. If the setting of this property does not exceed the current date, the cookie will expire after the task is over.
HasKeys Specifies whether the cookie contains keywords.
Path If specified, the cookie will be sent only to the request for the path. If this property is not set, the path to the application is used.
At this point, we have learned the theoretical knowledge of all the properties, methods and collections of Response objects. The author will demonstrate a simple program to deepen your understanding through practice. First, clip the following program into the notepad and save it as asp7.asp. (Note to remove the space between < and %!!!)
?
- <%
- Dimuser
- Dimflag
- Dimpwd
- Dimsay
- Response.buffer=true' enables buffering page function
- Response.ContentType=text/HTML
- Response.Charset=gb2312
- user=Request.Form(username)
- pwd=Request.Form(password)
- say=Request.QueryString(say)
- %>
- <formmethod=POSTaction=asp7.asp>
- <p>Username:<inputtype=textname=usernamesize=12><br>
- Password: <inputtype=passwordname=passwordsize=12><br>
- <inputtype=submitvalue=submit name=B1><inputtype=resetvalue=cancel name=B2></p></form>
- <%
- Ifsay=1then
- Response.Write welcomes scholars to come!
- EndIf
- Ifsay>1then
- Response.Write welcomes the scholar's ASP website again!
- EndIf
- Ifuser=Admandpwd=shushengThen
- Response.Expires=1'Set the page expires after being stored in the browser's buffer for 1 minute.
- flag=1
- ElseIfuser=guestandpwd=guestThen
- Response.Expires=0' causes the cached page to expire immediately.
- Response.Clear' Clear the page stored in the cache
- flag=2
- ElseIfuser=vipandpwd=vipThen
- Response.Write Welcomes VIP to the scholar's ASP website
- flag=3
- Else
- flag=0
- Response.End'Stop script processing immediately and outputs the cached page
- EndIf
- Response.write<p><ahref='asp7b.asp?flag=&flag&'>Eighteen martial arts of dynamic website design--ASP (7) Practical exercises</a>&l;/p>
- 'Transfer the value of the variable flag to asp7b.asp
- %>
- <p>Eighteen martial arts of dynamic website design--ASP (7) Practical exercises</p>
- Save the following program as asp7b.asp.
- <%
- Dimsaysay=Request.QueryString(flag)
- Selectcasesay
- case1
- Response.Redirectasp7.asp?say=1
- case2
- Response.Redirectasp7.asp?say=2
- case3
- Response.Redirectasp7.asp?say=3
- case0
- Response.Redirectasp7.asp?say=0
- EndSelect
- %>