The differences between response. Getwriter(). Write() and response. Getwriter(). Print(), as well as pritwriter object and out object

This article gives you a comprehensive understanding of Java object serialization and deserialization>>>

1、 The difference between response. Getwriter(). Write() and response. Getwriter(). Print()

Response. Getwriter() returns printwriter, which is a printout stream

Response. Getwriter(). Write() and response. Getwriter(). Print() are things that respond to the client. If you don’t use ajax to receive data and put it in the right place, a new page will be generated on the browser to display the content

Print
response. Getwriter(). Print(), can not only print out text format (including HTML tags), but also convert an object to binary byte output in the default encoding mode

write
response. Getwriter(). Write(), can only print out text format (including HTML tags), not objects

2、 The difference between the printwriter object and the out object obtained by response. Getwriter()

(1) The classes of out and response. Getwriter are different, one is jspwriter, the other is Java. Io. Printwriter

(2) The execution principle is different

Jspwriter is equivalent to a printwriter with cache function. Instead of directly outputting data to the page, it flushes the data to the response buffer and then outputs response. Getwriter directly outputs data (response. Print ()), so (out. Print) can only be outputted later

(3) Out is the built-in object of JSP, which refreshes the JSP page and automatically initializes to get the out object. Therefore, using the out object needs to refresh the page, and the response. Getwriter() response information is directly output to the web page. When the response ends, it is automatically closed, which has nothing to do with the JSP page, There is no need to refresh the page
figurative metaphor: when we call the response. Getwriter() object and get the brush of the web page at the same time, you can draw anything you want to display on the web page through the brush

(4) The print() method and println() method of response. Getwrite() method will generate IOException when the buffer overflows and there is no automatic refresh. The print and println methods of response. Getwrite() method will suppress IOException exception, and there will be no IOException, out. Println (‘); Method can’t wrap the page layout, but can only wrap the HTML code. To realize the page layout, you can: out. Println (“& lt/ br>”);

Similar Posts: