Difference between response. getwriter (). Write () and out. Print ()

Source: Internet
Author: User

1. first introduce the differences between the write () and print () methods:
(1), write (): only supports output of character type data, character, character array, String, etc.
(2) print (): Data of various types (including objects) can be converted to bytes by default encoding. These bytes are output through the write (INT c) method.
2. Introduce the differences between response. getwriter () and out:
(1) The out and response. getwriter classes are different. One is jspwriter and the other is Java. Io. printwriter.
(2) Different execution principles: jspwriter is equivalent to a printwriter with the cache function. Instead of directly outputting data to the page, it refreshes the data to the Response Buffer and then outputs the data,
Response. getwriter directly outputs data (response. Print (), so (Out. Print) can only be output after it.
(3) The out object is a built-in JSP object. Refresh the JSP page and obtain the out object automatically after initialization. Therefore, you need to refresh the page when using the out object,
The response information of response. getwriter () is output to the webpage through the out object. When the response ends, it is automatically disabled and is irrelevant to the JSP page. You do not need to refresh the page.
Image metaphor: When we call the response. getwriter () object to get the paint brush for the web page, you can use this paint brush to draw anything you want to display on the web page.
(4) The print () method of out and the println () method will generate an ioexception when the buffer overflow is not automatically refreshed,
The print and println of the response. getwrite () method both suppress the ioexception and do not have ioexception.

Out. println (""); the method cannot wrap the page layout. It can only wrap the HTML code. to wrap the page layout, you can: Out. println ("</BR> ");

 

Article Reprinted from: http://blog.csdn.net/javaloveiphone/article/details/8133772

 

Difference between response. getwriter (). Write () and out. Print ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.