Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is PrintWriter out = response.getWriter() in a Servlet?

I am new to Servlets.

Please, tell me about this line, and its use in the Jersey Framework + RESTful web services.

PrintWriter out = response.getWriter();
like image 523
user3498842 Avatar asked Sep 11 '14 06:09

user3498842


People also ask

What is PrintWriter out response getWriter ();?

getWriter(); returns the object of PrintWriter Class, in which print(String args) method is declared to print any thing on the browser's page as a response.

What is the use of response getWriter ()?

getWriter. Returns a PrintWriter object that can send character text to the client. The PrintWriter uses the character encoding returned by getCharacterEncoding() .

What is the function of PrintWriter in Java?

Class PrintWriter. Prints formatted representations of objects to a text-output stream. This class implements all of the print methods found in PrintStream . It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams.


1 Answers

In servlets the output can be either character or byte. for character data (i.e text) u can use PrintWriter for others use ServletOutputStream

PrintWriter: prints text data to a character stream. 

getWriter :Returns a PrintWriter object that can send character text to the client.
like image 121
Wahab Avatar answered Sep 19 '22 18:09

Wahab