JSP Out Implicit Object

Introduction:
1.    This implicit object is of type javax.servlet.jsp.JspWriter.
2.     This class is specially designed for Jsp’s to write data to the response.
3.     JspWriter  object (out) maintain buffer to store response data before write into the response object.
4.    Except this buffer there is no  difference  between  JspWriter and PrintWriter.
5.     Within the Jsp we can use either PrintWriter (or) JspWriter but not recommended to use both simultaneously.
6.     JspWwriter is the child class of Writer hence all methods of Writerclass are by default available to the JspWriter through inheritance.
7.     In addition to these methods JspWriter can contain two methods  print() & printIn ( ) methods to add any type of response to the Jsp.

Methods of out Object:
There are numerous methods available for out Object, such as:

1.clear
As the name implies, the clear method of out object is used to clear the output buffer. An exception is thrown by this method if the buffer was flushed.
2.clearBuffer
The clearBuffer method of out object is used to clear the output buffer. clearBuffer method does not throw an exception when the buffer is flushed.
3.flush
Two methods of out object, clear and clearBuffer are used to clear the output buffer without writing any contents to the client.
4.isAutoFlush
The isAutoFlush method of out object returns a true value if the output buffer is automatically flushed.
5.getBufferSize
The getBufferSize method of out object is used to return the size of the buffer. The returned value of the size of the buffer is in bytes. If the output is not buffered, then the getBufferSize method returns a 0 byte.
6.getRemaining
The getRemaining method of out object is used to return the number of empty bytes in the buffer.
7.newLine
As the name implies, the newLine method of out object is used to write a newline character to the output.
8.print
The print method of out object writes the value to the output without a newline character.
9.println
The println method of out object is used to write the value to the output, including the newline character.

Note :  JspWriter =  PrintWriter+Buffer

Example: test.jsp

<%@ page session="true" %>
<%
application.setAttribute("SITE", "MYJAVAHUB.COM");
%>
<table border= 2>
<%
out.println("<tr><td>Buffer Size : </td><td>" + out.getBufferSize()+"</td></tr>");
out.println("<tr><td>Is AutoFlush Enable</td><td> " + out.isAutoFlush()+"</td></tr>");
out.println("<tr><td>Remaining Buffer Size </td><td>" + out.getRemaining()+"</td></tr>");
out.println("<tr><td>SITE </td><td>" + application.getAttribute("SITE")+"</td></tr>");
%>
</table>



Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

No comments:

Post a Comment