what is PrintWriter out = response.getWriter() in servlet

喜欢而已 提交于 2019-12-18 11:20:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!