BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Out Implicit Object in JSP with examples

Last Updated: July 27, 2022 by Chaitanya Singh | Filed Under: JSP tutorial

In this tutorial, you will learn out implicit object in JSP with the help of examples. It is an instance of javax.servlet.jsp.JspWriter. This allows user to access Servlet output stream. The output which needs to be sent to the client (browser) is passed through this object. Simply put, the JSP out implicit object is used to write content to the client.

Methods of out implicit object

  1. void print(): This method writes the value that is passed into it. For example, the following statement would display a message “Out Implicit Object in jSP – BeginnersBook” on the output screen (client browser).
    out.print(“Out Implicit Object in jSP - BeginnersBook”);
  2. 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.
    when using print():

    out.print(“hi”);
    out.print(" ");
    out.print(“hello”);

    output: There will not be a new line between the outcomes of all 3 out.print() statements.

    hi hello

    when using println():

    out.println(“hi”);
    out.println(“hello”);

    output:

    hi
    hello
  3. void newLine(): This method adds a new line in the output. Example:
    out.print(“This will write content without a new line”);
    out.newLine();
    out.print(“I’m just an another print statement”);

    Output:

    This will write content without a new line
    I’m just an another print statement

    As we learned that print statement doesn’t add a new line. We have added a new line between two out.print() statements using newLine() method.

  4. void clear(): It clears the output buffer even if the content in the buffer is not written on the client. This is how it can be called:
    out.clear();
  5. void clearBuffer(): This method is similar to the clear() method. The only difference between them is that when we call out.clear() on an already flushed buffer it throws an exception, however out.clearBuffer() doesn’t throw any exception even if the buffer is already flushed.
  6. 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 the buffer is cleared.
  7. boolean isAutoFlush() :  It returns a Boolean value true/false. It is used to check whether the buffer is automatically flushed or not. If buffer is flushed, it returns true else it returns false.
  8. int getBufferSize(): This method returns the size of output buffer in bytes.
  9. int getRemaining(): It returns the number of bytes remaining before hitting the buffer overflow condition.

JSP out implicit object Example

In this example we are using print() and println() methods of out object to print messages on the output screen.
index.jsp

<HTML>
<HEAD> 
<TITLE> OUT IMPLICIT OBJECT EXAMPLE </TITLE>
</HEAD>
<BODY>
<%
out.print( "print statement " );
out.println( "println" );
out.print("Another print statement");
%>
</BODY>
</HTML>

Output:

print statement println
Another print statement
❮ JSP sessionJSP pageContext ❯

Top Related Articles:

  1. JSP Scriptlet Tag (Scripting elements)
  2. Java Server Pages (JSP) Life Cycle
  3. Config Implicit Object in JSP with examples
  4. Include Directive in JSP
  5. Exception Implicit Object in JSP with examples

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSP Tutorial

  • Basics of JSP
  • Life cycle of JSP
  • JSP in Eclipse IDE

Scripting Elements

  • Scriptlet Tag
  • Expression tag
  • Declaration tag

Implicit Objects

  • Implicit Objects
  • JSP Request
  • JSP Response
  • JSP Config
  • JSP Application
  • JSP Session
  • JSP Out
  • JSP pageContext
  • JSP Exception
  • Validate session

JSP directives

  • JSP Directives
  • Include Directive

JSP Exception

  • Exception handling

JSP Action

  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty

Expression language

  • Expression language

JSP Custom Tags

  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap