OUT Implicit Object in JSP with examples:
It’s an instance of javax.servlet.jsp.JspWriter. This allows us to access Servlet output stream. The output which needs to be sent to the client (browser) is passed through this object. In simple words out implicit object is used to write content to the client.
Methods of OUT Implicit Object:
Let’s here see each of the out’s method in detail:
void print(): This method writes the value which has been passed to it. For e.g. the below statement would display a sentence Out Implicit Object in jSP
out.print(“Out Implicit Object in jSP ycd”);
void println(): This method is similar to the print() method, the only difference between print and println is that the println() method adds a new line character at the end. Let’s have a look at the difference with the help of an example.
void newLine(): This method adds a new line to the output. Example –
out.print(“This will write content without a new line”);
out.print(“I’m just an another print statement”);
As you know print statement doesn’t add a new line. We have added a new line between two out.print statements using newLine() method.
void clear(): It clears the output buffer without even letting it write the buffer content to the client. This is how it can be called –
void clearBuffer(): This method is similar to the clear() method. The only difference between them is that when we invoke out.clear() on an already flushed buffer it throws an exception, however out.clearBuffer() doesn’t.
void flush() : This method also clears the buffer just like clear() method but it forces it to write the content to the output before flushing it, which means whatever is there in buffer would be written to the client screen before clearing the buffer.
boolean isAutoFlush() : It returns a Boolean value true/false. It is used to check whether the buffer is automatically flushed or not.
int getBufferSize(): This method returns the size of output buffer in bytes.
int getRemaining(): It returns the number of bytes remaining before hitting the buffer overflow condition.
OUT Implicit Object Example
In this example we are using print and println methods of OUT for displaying few message to the client.
<TITLE> OUT IMPLICIT OBJECT EXAMPLE </TITLE>
out.print( "print statement " );
out.println( "println" );
out.print("Another print statement");