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

user3498842 picture user3498842 · Sep 11, 2014 · Viewed 83.1k times · Source

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();

Answer

Wahab picture Wahab · Sep 11, 2014

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.