In this Section, we will discuss about implicit object out & it's methods.
Out object denotes the Output
stream in the context of page. The class or the interface name of the object out is
"jsp.JspWriter". This object is instantiated implicitly from JSP Writer
class and can be used for displaying anything within delimiters.
Methods in out object
(1)print() : The print method of out object writes the value to the output without a newline character.
If a JSP program has the following statements :
(2)println() : The println method of out object writes the value to the output with a newline character.
| Welcome!!! |
(3)newLine : The 'newLine' method of out object is used to write a newline character to the output.
Example : If a JSP program has the following statements :
The clear method of out object is used to clear the output buffer. This method does not write any contents to the client. An exception is thrown by this method if the buffer was flushed.
Syntax : out.clear() ;
The 'clearBuffer' method of out object is used to clear the output buffer. This method does not write any contents to the client. The only difference between the 'clear' method of out object and 'clearBuffer' method is
(6)flush : Two methods of out object, 'clear' and 'clearBuffer' are used to clear the output buffer without writing any contents to the client. The 'flush' method of out object is used to flush the buffer by writing the contents to the client.
In the above example, no forwarding will take place. This is because of the "out.flush()" method. This method will flush the "JspWriter" buffer. Once the content is written to the browser, a forward cannot be invoked.
(7)isAutoFlush() : The "isAutoFlush" method of 'out' object returns a 'true' value if the output buffer is automatically flushed otherwise returns 'false'.
Syntax: out.isAutoFlush() ;
(8)getBufferSize : The "getBufferSize" method of 'out' object is used to return the size of the buffer. The returned value of the size of the buffer is in bytes. If the output is not buffered, then the "getBufferSize" method returns a 0 byte.
(9)getRemaining() : The "getRemaining" method of out object is used to return the number of empty bytes in the buffer.
Syntax : out.getRemaining() ;
EXAMPLE USING "out" OBJECT
<%// This scriptlet declares and initializes "date"
System.out.println("Evaluating date now" );
java.util.Date date =new java.util.Date();
Hello! The time is now
out.println( date );
out.println("<BR>Your machine's address is " );
Recommend the tutorial