12.6 The buffer and autoFlush Attributes

The buffer attribute specifies the size of the buffer used by the out variable, which is of type JspWriter . Use of this attribute takes one of two forms:

 
 <%@ page buffer="  size  kb" %> <%@ page buffer="none" %> 

Servers can use a larger buffer than you specify, but not a smaller one. For example, <%@ page buffer="32kb" %> means the document content should be buffered and not sent to the client until at least 32 kilobytes are accumulated , the page is completed, or the output is explicitly flushed (e.g., with response.flushBuffer ). The default buffer size is server specific, but must be at least 8 kilobytes. Be cautious about turning off buffering; doing so requires JSP elements that set headers or status codes to appear at the top of the file, before any HTML content. On the other hand, disabling buffering or using a small buffer is occasionally useful when it takes a very long time to generate each line of the output; in this scenario, users would see each line as soon as it is ready, rather than waiting even longer to see groups of lines.

The autoFlush attribute controls whether the output buffer should be automatically flushed when it is full (the default) or whether an exception should be raised when the buffer overflows ( autoFlush="false" ). Use of this attribute takes one of the following two forms.

 
 <%@ page autoFlush="true" %> <%-- Default --%> <%@ page autoFlush="false" %> 

A value of false is illegal when buffer="none" is also used. Use of autoFlush="false" is exceedingly rare when the client is a normal Web browser. However, if the client is a custom application, you might want to guarantee that the application either receives a complete message or no message at all. A value of false could also be used to catch database queries that generate too much data, but it is generally better to place that logic in the data access code, not the presentation code.



Core Servlets and JavaServer Pages (Vol. 1.Core Technologies)
Core Servlets and Javaserver Pages: Core Technologies, Vol. 1 (2nd Edition)
ISBN: 0130092290
EAN: 2147483647
Year: 2002
Pages: 194

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net