Methods in out object
The print method of out object writes the value to the output without a newline character.
If a JSP program has the following statements :
out.print("Welcome!!!"); out.print("To dineshonjava.com");
The println method of out object writes the value to the output with a newline character.
The ‘newLine’ method of out object is used to write a newline character to the output.
Example : If a JSP program has the following statements :
out.write("Welcome!!!"); out.newLine(); out.write("Dinesh");
The clear method of out object is used to clear the output buffer. This method does not write any contents to the client. An exception is thrown by this method if the buffer was flushed.
Syntax : out.clear() ;
The ‘clearBuffer’ method of out object is used to clear the output buffer. This method does not write any contents to the client. The only difference between the ‘clear’ method of out object and ‘clearBuffer’ method is ‘clear’ method throws an exception when the buffer is flushed. ‘clearBuffer’ method does not throw an exception when the buffer is flushed.
if (out.getBufferSize() != 0) out.clearBuffer();
Two methods of out object, ‘clear’ and ‘clearBuffer’ are used to clear the output buffer without writing any contents to the client. The ‘flush’ method of out object is used to flush the buffer by writing the contents to the client.
out.flush(); <jsp:forward page="hello.jsp"/>
In the above example, no forwarding will take place. This is because of the “out.flush()” method. This method will flush the “JspWriter” buffer. Once the content is written to the browser, a forward cannot be invoked.
The “isAutoFlush” method of ‘out’ object returns a ‘true’ value if the output buffer is automatically flushed otherwise returns ‘false’.
Syntax: out.isAutoFlush() ;
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.
if (out.getBufferSize() != 0) out.getBufferSize()
The “getRemaining” method of out object is used to return the number of empty bytes in the buffer.
Syntax : out.getRemaining() ;
JSP out Object Example:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>JSP pageContext Object Example</title> </head> <body> <% out.println("Hello Dinesh!!!!!!"); %> </body> </html>
Output on browser: Hello Dinesh!!!!!!
As you can see above, using JSP out object, String response is displayed on the browser when JSP served a request.
Copy implicitobjects folder on webapp directory of tomcat at
C:Program Files (x86)Apache Software FoundationTomcat 7.0webapps
and restart server and hit the following URL