问题
I am new to Servlets.
please tell me about this line: and doing in jersey framework + REstful web services. Any help regarding Jersey framework
PrintWriter out = response.getWriter();
回答1:
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.
回答2:
in this case, the servlet binded with the url-pattern (previously set) is called.
The method being called depends on the kind of request (doGet, doPost, doPut).
The method normally receives the request and response objects, we then call the .getWriter() method for the response obj that gets us the stream on which we can write our output.
response.getWriter() returns a PrintWriter object that can send character text to the client.
Calling flush() on the PrintWriter commits the response.
回答3:
res.getWriter(); returns the object of PrintWriter Class, in which print(String args) method is declared to print anything on the browser's page as a response.
回答4:
Simple just have a look again
Printwriter out = response.getWriter()
Now, here Printwriter is a class which simply converts the bytes into normal characters which we want to show as a response to the client's browser.So first you define out
as a Printwriter object and through the GetWriter method we get the instance.
回答5:
dnt be confused its simple as we had created object OUT of class PRINTWRITER nd simply returned as response by using GETWRITER METHOD.
来源:https://stackoverflow.com/questions/25780467/what-is-printwriter-out-response-getwriter-in-servlet