Open In App

JSP – Out Implicit Object

Last Updated : 03 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In Java, JSP stands for JavaServer Pages. It is a technology that can used for creating dynamic web pages in Java and the Out implicit object in JSP is used to send content to the web client for rendering.

In this article, we will discuss the concept of Out implicit object in JSP.

Out Implicit Object

The Out implicit object in the JSP can provide a way to send the content to the response stream which is then rendered on the web page. It is mainly used to display the dynamic content generated by the JPS codes.

Steps to Use Out Implicit Object:

  • We can access the Out implicit object within the JSP Code.
  • Use methods like print( ) or println() to send the content to the response stream.
  • Then the content can be sent using Out and is directly rendered on the web page when the response is sent to the client.

Using Out.print() method:

The print() method can be used to the Out implicit objects sends content to the response stream without appending the new line character.

Example:

<body>
<%
// Using Out.print() to send content
out.print("This is printed using Out.print(). ");
out.print("No new line character is appended.");
%>

Using Out.println() method:

The println() method can be used to the Out implicit object sends content to the response stream and it can append the new line character after the content.

Example:

<body>
<%
// Using Out.println() to send content
out.println("This is printed using Out.println().");
out.println("A new line character is appended after each println() call.");
%>

Flushing the Output:

Flushing can be used to the output ensures that the content can sent using Out is immediately sent to client’s browser instead of waiting for the buffer to be filled.

Example:

<body>
<%
// Using Out.println() to send content
out.println("This content is flushed immediately.");

// Flush the output to ensure it's sent immediately
out.flush();
%>

Directives to Control Output:

JSP directives like <% page buffer = “none” %> can be used to the control of buffering behavior and it can affecting how the content sent using the Out is handled.

Example:

<body>
<%
// Send content using Out implicit object
out.println("This content is not buffered because buffer=\"none\" directive is used.");
%>

Note: If you are beginner refer the link to create the JSP project and execution of the JSP application.

Program to Implement Out Implicit Object of JSP

Below is a working code example to demonstrate the implementation of Out Implicit Object of JSP.

HTML
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Out Implicit Object Example</title>
</head>
<body>
    <%
        // Using Out.print() method
        out.print("Hello, this is printed using Out.print()<br>");

        // Using Out.println() method
        out.println("This is printed using Out.println()");
    %>
</body>
</html>

Output:

Hello, this is printed using Out.print()
This is printed using Out.println()

Output Image:

Below is the Output image for better understanding.

Browser Output

Note: URL could vary depending on the server’s port number and context path.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads