ASP response. Flush real-time display progress

Source: Internet
Author: User
Tags blank page

Write Program When writing HTML for static pages generated by ASP pages, if a large number of pages are generated at the same time, the progress bar at the bottom of the browser must display 3%, 6%, 10% and so on. In this waiting process, you don't know which record the page has generated, and you can only stare at it.

If you know response. Flush and response. Clear, you don't have to wait like this. Every time an HTML page is generated, a message is immediately returned using response. Write, prompting that the database record has generated HTML.

In this way, when a large number of pages are generated at the same time, you are no longer alone looking at a blank page, but the progress bar slowly changing under the browser is in a daze, you can always know which database records have been generated. Even if an accident occurs, such as a crash or power failure, you also know the next time you generate a record, you should start generating HTML again. Is it nice? This is a progress bar and more specific.

Well, don't worry. Let's first look at the meaning of response. Flush and response. Clear.

The flush method of the response object to send the output in the buffer immediately. If response. buffer is not set to true, this method will cause a runtime error. Syntax: Response. Flush; Note: If the flush method is called on the ASP page, the server will respond to requests that keep the page active. Apply to the response object.

The buffer section is described here. Buffer is called a buffer, because it is not only a noun, but also a verb.

The buffer zone stores a series of data. The data obtained by the client can be directly output from the execution results of the program or the buffer zone. However, the two methods differ in speed: in the Web, when an ASP program is requested for a small number of times, there is basically no difference between the two, at least we do not feel it. However, when many people request an ASP program, the speed may be different. If there is no buffer, the result obtained by the client of each person requesting the ASP program is the result obtained by executing the ASP program once. If the ASP program is buffered in advance, the result obtained by each client is the result of the buffer, not the result of executing a program. For example, if 1000 users access an ASP page at the same time, if the ASP program is not buffered, the program will be executed one thousand times, so that the server load will increase, this slows down the page opening speed of the client. If the ASP program is buffered, the results will be different. Each client obtains data directly from the buffer zone, the server will not increase the number of program executions because of the increase in access, so the client can open the page faster than in the previous case. This is the benefit of buffer.

The response. Clear and clear methods delete all HTML output in the buffer. However, the clear method only deletes the response body without deleting the response title. You can use this method to handle errors. Note that if response. buffer is not set to true, this method will cause a runtime error. Syntax: Response. Clear; applies to response objects.

Well, to achieve immediate output, you only need to add response. Flush and response. Clear to the Message output in the loop body. For example:

<%
For 1 to 2000
For I1 = 1 to 3000
''Empty loop, prolong each execution time
Next
Response. Write I &")"
Response. Flush
Response. Clear
Next
%>

After you execute the above ASP statements, you will find that the output is output one by one. Once executed, it is output once.

However, some people on the Internet said, "Many times, we find that even if we use response. Flush (), the previous information is not sent to the client for display. The white screen is still presented to us. After repeated tests, I came to the conclusion that flush should contain at least 256 bytes. That is, only when the compilation generates at least 256 bytes of data can the information be sent to the client and displayed after response. Flush () is executed ."

It is strange that the statements I have provided have indeed achieved the display effect one by one, and no 256 bytes have been output in advance. You can save the statements as NotePad to run them, the results are displayed row by row. The points listed in this article only represent flymorn's personal point of view and will not be used for other purposes.

If you do need to output 256 bytes in advance, you can:

<%
Dim liji
For 1 to 256
Liji = liji & "<! -- Generate 256 characters first-www. piaoyi. org -->"
If Len (liji)> = 256 then exit
Next
%>
If you have different opinions or different test results, please join me for discussion.

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.