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

I am new to servlets.

please tell me about this line: and in jersey framework + REstful web services. Any help regarding the jersey frame

PrintWriter out = response.getWriter(); 
+9
source share
5 answers

In servlets, the output can be either a character or a byte. for character data (e.g. text) you 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. 
+14
source

in this case, the servlet associated with the url template (previously set) is invoked.

The method invoked depends on the type of request (doGet, doPost, doPut).

Typically, a method receives request and response objects, then the .getWriter () method is called to respond obj, which receives a stream to which we can write our output.

response.getWriter () returns a PrintWriter object that can send text to the client.

The call to flush () on PrintWriter is responsible for the response.

+3
source

res.getWriter (); returns an object of the PrintWriter class in which a printing method (String args) is declared for printing anything on the browser page as an answer.

0
source

Just take a look again

 Printwriter out = response.getWriter() 

Now here, Printwriter is a class that simply converts bytes to regular characters, which we want to display in response to the client’s browser. So, first you define out as a Printwriter object and through the GetWriter method we get an instance.

0
source

dnt confuse it, we just created an OUT object of the PRINTWRITER class and simply returned as a response using the GETWRITER method.

-2
source

Source: https://habr.com/ru/post/975110/


All Articles