In the previous article, the author gave you a detailed introduction to the use of request, one of ASP built-in objects. I believe that you can master it through a series of practices, this article will continue to introduce ASP's other built-in object response. Recently, many friends have come to "Mei Er" to urge me to speed up asp Writing and eagerly ask where there are ASP teaching materials. I was deeply touched by everyone's enthusiasm for learning, so I decided to share some ASP information I have collected at ordinary times with everyone, I also hope that all my friends will generously tell the author about ASP. Thank you. Currently, Chinese ASP teaching materials are rare in China, and the authors of Chinese teaching materials specially developed for ASP websites are even more unknown (probably the authors are ignorant ), I just recently heard of a dumb book about MS InterDev published by Tsinghua University Press, which includes ASP teaching and a Chinese manual of Active Server Page 2.0, therefore, at present, the author mainly obtains ASP-related information and materials through foreign websites, which is also a major reason for the author to write this article. Below I will list some classic ASP sites in Bookmark:
1. http://www.activeserverpage.com/
This is the most frequently visited ASP Website by the author and one of the largest and most comprehensive ASP websites in the world. It not only contains the latest ASP documents and free components, there is also a complete ASP entry-level teaching material, which is also the central site of the ASP Website, through which you can reach countless ASP-related sites.
2. http://www.asphole.com/
This is a site built for ASP vulnerabilities, but it is undoubtedly a complete ASP information site. It not only provides ASP articles, and components also provide detailed and thorough connection addresses.
3. http://www.15seconds.com/faq and http://www.15seconds.com/search
This is the largest online ASP communication site seen by the author. It has answers to questions from ASP, ASP mail list information, and ASP skills, it may take several months for you to read the information. While in the http://www.15seconds.com/AllComponents.asp you can read the latest ActiveX components and a large number of free components detailed introduction, with very practical documentation and examples.
4. http://www.microsoft.com/workshop/server/asp/aspfeat.asp
As we all know, the Active Server Page is a set of web server environment based on nt iis proposed by Microsoft. Therefore, the ASP Technology set up by Microsoft indicates the site.
5. http://www.serverobjects.com/
Here you can get countless practical ActiveX components and download their trial versions. Unfortunately, most of the excellent components require money.
6. http://www.cyscape.com/asp/browscap/
Do you still remember the browser capabilitie component introduced by the author in asp2 to identify the browser version of the client? You can get the latest browscap on this site. INI file, which has information about the browsers that Microsoft does not provide when installing ASP, so that you can determine whether the client browser is safe in ASP.
7. http://www.microsoft.com/data/ado/
ASP has the most powerful and convenient functions than connecting to a database. with ASP's built-in ActiveX components, we can easily connect the web with all ODBC-compatible databases, on this Microsoft site, you can obtain a lot of practical ADO information.
8. http://www.cobb.com/m_sbn4/
A good ASP forum where you can post your questions and read others' questions and answers.
Next, we start to learn another built-in ASP object response.
Unlike request, which is used to obtain the HTTP information of the client, 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 cookie value.
Syntax
Response. Collection | property | Method
I. Attributes
1. Buffer
The buffer attribute indicates whether to buffer page output. When the buffer page is output, the server sends the response to the client browser only after all the server scripts on the current page are processed or the flush or end method is called, after the server sends the output to the client browser, the buffer attribute cannot be set. Therefore, response. buffer should be called in the first line of the. asp file.
2. charset
The charset attribute attaches the character set name to the end of the Content-Type title in the response object. For ASP pages that do not contain the response. charset attribute, the Content-Type title is: Content-Type: text/html.
You can specify the Content-Type title in the. asp file, for example:
<% Response. charset = "gb2312") %>
The following results are generated:
Content-Type: text/html; charset = gb2312
Note: This function inserts a string into the Content-Type title regardless of whether the character set is valid. If a page contains multiple tags containing 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 on this page.
3. contenttype
The contenttype attribute specifies the HTTP content type of the server response. If contenttype is not specified, the default value is text/html.
4. Expires
The expires attribute specifies the time before the page cached on the browser expires. If you return to this page before a page expires, the page in the buffer zone is displayed. If response. expires is set to 0, the cached page can expire immediately. This is a more practical attribute. When you enter the web site through ASP login page, you should use this attribute to immediately expire the login page to ensure security.
5. expiresabsolute
Different from the expires attribute, the expiresabsolute attribute specifies the exact expiration date and time of the page cached in the browser. If you return to this page before expiration, the page in the cache is displayed. If no time is specified, the home page will expire at midnight that day. If no date is specified, the home page will expire at the specified time on the day when the script runs. The following example specifies that the page will expire at a.m. on January 1, December 10, 1998.
<% Response. expiresabsolute = # dec 12,1998 9:00:30 # %>
Ii. Method
1. Clear
You can use the clear method to clear all HTML output in the buffer. However, the clear method only clears the response body without clearing the response title. You can use this method to handle errors. However, if response. buffer is not set to true, this 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 has been set to true, call response. End to buffer the output.
3. Flush
The flush method immediately sends the output in the buffer. If response. buffer is not set to true, this method will cause a runtime error.
4. Redirect
The redirect method redirects the browser to the URL specified by the program immediately. 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 based on different responses of customers. Once the Redirect method is used, any response body content explicitly set on the page will be ignored. However, this method does not send other HTTP headers set for this page to the client, and generates an automatic response body that uses the redirected URL as the link. The redirect method sends the following explicit headers, where the URL is the value passed to the method. For example:
<% Response. Redirect ("www.chinabyte.com") %>
5. Write
The write method is one of the most commonly used methods. It writes the specified string to the current HTTP output.
Iii. Set
The response object has only one set-cookie
Set the cookie value in the cookie set. If the specified cookie does not exist, create it. If yes, a new value is set and the old value is deleted.
Syntax
Response. Cookies (cookies) [(key) |. Attribute] = Value
Here, the cookie is the name of the specified cookie. If the key is specified, the cookie is a dictionary. Attribute specifies information about the cookie itself. Attribute can be one of the following:
If the domain is specified, the cookie will be sent to the request for this domain.
Expires specifies the cookie expiration date. This date must be set to store cookies on the client disk after the session ends. If the setting of this attribute does not exceed the current date, the cookie will expire after the task ends.
Haskeys specifies whether the cookie contains a keyword.
If path is specified, the cookie will only be sent to the request for this path. If this attribute is not set, the Application Path is used.
So far, we have learned all the attributes, methods, and set theoretical knowledge of the response object. The author below will show you a simple program to help you better understand through practice. First, cut the following program into the workbook and save it as asp7.asp. (Remove the space between <and % !!!)
<%
Dim user
Dim flag
Dim pwd
Dim say
Response. Buffer = true' enable the page caching 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 = "12"> <br>
Command: <input type = "password" name = "password" size = "12"> <br>
<Input type = "Submit" value = "Submit" name = "B1"> <input type = "reset" value = "cancel" name = "B2"> </P> </form>
<%
If say = 1 then
Response. Write "Welcome to Shusheng! "
End if
If say> 1 then
Response. Write "welcome to the ASP Website of Scholar again! "
End if
If user = "ADM" and Pwd = "Shusheng" then
Response. expires = 1' sets the page to expire after being stored in the browser buffer for 1 minute.
Flag = 1
Elseif user = "guest" and Pwd = "guest" then
Response. expires = 0' causes the cached page to expire immediately.
Response. clear' clear the pages stored in the cache
Flag = 2
Elseif user = "VIP" and Pwd = "VIP" then
Response. Write "Welcome VIP to the ASP Website of scholar"
Flag = 3
Else
Flag = 0
Response. end' stop script processing immediately and output the page in the cache
End if
Response. Write "<p> <a href = 'asp7b. asp? Flag = "& flag &" '> 18 martial arts of dynamic website design-Asp (7) Practical Exercises </a> </P>"
'Send the flag value of the variable to asp7b. asp
%>
<P> 18 martial arts for dynamic website design-Asp (7) Practical Exercises </P>
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 in the Web virtual directory with execution permissions and access asp7.asp over HTTP. In these two programs, we fully utilize the two asp built-in objects learned so far: request and response. When you access the asp7.asp file for the first time, a form is displayed on the page, prompting you to enter the user name and password. If you enter the User name: ADM, password: Shusheng, the following page appears:
Why? Because we have set the page cache, when using guest to log on, it determines that the program automatically clears all the pages stored in the cache, and only displays the results of subsequent script execution.
Why is only one form dialog box displayed when I log on to the asp7.asp page for the first time? At this time, the program judges that the user is neither ADM nor guest or VIP, so it 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 use ADM, guest, or VIP to log on to this page, you can see a hyperlink that points to the file asp7b. ASP. When we click this hyperlink, asp7.asp sends the flag value of the variable to asp7b as a parameter. ASP, while the latter makes a judgment based on the value of this parameter, and uses response according to different situations. redirect then forcibly returns asp7.asp, and sends the value of a variable say to asp7.asp as a parameter. In this way, asp7.asp will make different responses based on this parameter.
Now we can see that we only use two simple programs to display different results on the same page. This is the charm of ASP, you can make some changes based on this demonstration program to master the two built-in objects we have learned. Today's course ends. I have to explain two things at the end. First, many of my friends asked me where I could see the first few ASP articles. Please click here to find them. Second, some friends reported that the ASP program in the article could not run. This is mainly because the chinabyte pages are all generated by the database. It is restricted to the use of code with HTML or ASP format in the article, therefore, spaces are added after all <symbols. You only need to remove the spaces after <to run the program. Remember. In the next article, we will continue to learn another ASP built-in object, so stay tuned.