The Out Object in JSP

By: Sathya Narayana Emailed: 1705 times Printed: 2206 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

The out object is an instance of the javax.servlet.jsp.JspWriter class. It's used to create the content returned to the client and has the following useful methods available.

clear() clears the contents of the buffer; it throws an exception if some data has already been written to the output stream:

public abstract void clear()
throws java.io.IOException

clearBuffer() clears the contents of the buffer but doesn't throw an exception if some data has already been written to the output stream:

public abstract void clearBuffer()
throws java.io.IOException

close() flushes and then closes the output stream:

public abstract void close()
throws java.io.IOException

flush() flushes the output buffer and sends any bytes contained in the buffer to their intended destination. flush() will flush all the buffers in a chain of Writers and OutputStreams:

public abstract void flush()
throws java.io.IOException

getBufferSize() returns the size in bytes of the output buffer:

public int getBufferSize()

getRemaining() returns the number of bytes still contained in the buffer. It will return 0 if it's unbuffered:

public abstract int getRemaining()

isAutoFlush() returns true if the buffer flushes automatically when an overflow condition occurs:

public boolean isAutoFlush()

newLine() writes a new line character to the output stream:

public abstract void newLine()
throws java.io.IOException

print() prints the specified primitive data type, Object,or String to the client:

public abstract void print(boolean b)
throws java.io.IOException
public abstract void print(char c)
throws java.io.IOException
public abstract void print(int i)
throws java.io.IOException
public abstract void print(long l)
throws java.io.IOException
public abstract void print(float f)
throws java.io.IOException
public abstract void print(double d)
throws java.io.IOException
public abstract void print(char[] s)
throws java.io.IOException
public abstract void print(String s)
throws java.io.IOException
public abstract void print(Object obj)
throws java.io.IOException


Here's an example:

<%
try
{
boolean b = false;
out.print(b);

}
catch(java.io.IOException ioe)
{
//Catch error.
}
%>

The previous will print false in the browser window.

println() prints the specified primitive data type, Object, or String to the client, followed by a new line character at the end. The no-argument version simply writes a new line character:

public abstract void println()
throws java.io.IOException
public abstract void println(boolean x)
throws java.io.IOException
public abstract void println(char x)
throws java.io.IOException
public abstract void println(int x)
throws java.io.IOException
public abstract void println(long x)
throws java.io.IOException
public abstract void println(float x)
throws java.io.IOException
public abstract void println(double x)
throws java.io.IOException
public abstract void println(char[] x)
throws java.io.IOException
public abstract void println(String x)
throws java.io.IOException
public abstract void println(Object x)
throws java.io.IOException

For example:

<%
try
{
out.println("<html><title>Page Title</title></html>");
}
catch(java.io.IOException ioe)
{
//Catch error.
}
%>


JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sathya Narayana
Querying Data with the JSTL in JSP
Deleting Data in MySQL
Modifying data and using WHERE clause in MySQL
Querying the Database in MySQL
Inserting Data into Tables in MySQL
Changing the Structure of an Existing Table in MySQL
The Exception Object in JSP
The Application Object in JSP
The Session Object in JSP
The Out Object in JSP
The Response Object in JSP
The Request Object in JSP
Tag Libraries in JSP
Scriptlets and Expressions in JSP
Declarations in JSP

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
Automatically Refreshing a JSP
JSP Alert Example
JSP Example to connect to MS SQL database and retrieve records
What are the different scopes in JSP?
JSP CheckBox Example
Radio Object
Example Using Initialization Parameters
Arithmetic Evaluation Using the Expression Language in JSP
JSP Program for display Date
Password Object
Comparison operators in JSP
Using a DataSource from WebLogic in a JSP
Tag libraries
Techniques for form editing
NetworkClient
Most Emailed Articles (in JSP)
What is JSP?
Techniques for form editing
Closing Windows
Retrieving a Portion of a String
Server-side plug-Ins
Web Security Issues
The page Directive in JSP
Uploading an Image to a Database using JSP
JSP CheckBox Example
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Syntax For JSP Declaratives
JSP Directives