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");