Both approaches are valid, and thus both are supported in the JSP technology. The behavior 
of a page is controlled by the 
autoFlush
 attribute, which defaults to true. In general, JSP 
pages that need to be sure that correct and complete data has been sent to their client may 
want to set 
autoFlush
 to 
false
, with a typical case being that where the client is an 
application itself. On the other hand, JSP pages that send data that is meaningful even when 
partially constructed may want to set 
autoFlush
 to 
true
; a case may be when the data is 
sent for immediate display through a browser. Each application will need to consider their 
specific needs.
An alternative considered was to make the buffer size unbounded, but this has the 
disadvantage that runaway computations may consume an unbounded amount of resources.
The 
JspWriter
 interface includes behaviors from 
java.io.BufferedWriter
 and 
java.io.PrintWriter
 API's but incorporates buffering and does not consume 
IOExceptions as PrintWriter does. If a particular use requires a PrintWriter, as in the case of 
desiring to insert an exception stack trace, one can be obtained by wrapping the JspWriter 
with a PrintWriter.
The usual methods found in PrintWriter are available with the only modification being that 
the JspWriter methods do not consume IOExceptions. The additional methods are:
clear()
This method is used to clear the buffer of data. It is illegal to invoke it if the JspWriter 
is not buffered. And exception will be raised if the buffer has been autoFlushed and 
clear() is invoked. Also see clearBuffer().
The method signature is 
void clear()
clearBuffer()
This method is like clear() except that no exception will be raised if the buffer has been 
autoFlushed().
The method signature is 
void clearBuffer()
.
flush()
This method is used to flush the buffer of data. The method may be invoked indirectly 
if the buffer size is exceeded. The underlying PrintWriter object is guaranteed to be 
created exactly the first time data is flushed to it.
The method signature is 
void flush()
close()
This method can be used to close the stream. It needs not be invoked explicitly for the 
initial JspWriter as the code generated by the JSP container will automatically include 
a call to close().
The method signatures is 
void close().
getBufferSize()
This method returns the size of the buffer used by the JspWriter.
The method signatures is 
int getBufferSize()
getRemaining()
This method returns the number of unused bytes in the buffer.
The method signature is 
int getRemaining()
Appendix 6
JSP Technology Classes
116




JSP Web Hosting JavaServer Pages Specifications JSP Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.