Write () and print () also have <%=%> subtle differences

Source: Internet
Author: User

1. First introduce the difference between the write () and print () methods:

(1), write (): Supports output character type data only, character, character array, string, etc.

(2), print (): The data of various types (including object) can be converted into bytes byte form by default encoding, which is output by the write (int c) method

2, introduce the difference between response.getwriter () and out:

(1), out and Response.getwriter classes are not the same, one is JspWriter, the other is java.io.PrintWriter.

(2), the principle of implementation is different: JspWriter is equivalent to a printwriter with a cache function, it does not directly output data to the page, but the data is flushed to the response buffer and then output, Response.getwriter Direct output data (Response.print ()), so (Out.print) can only be output thereafter.

(3), out for the JSP's built-in object, refresh the JSP page, automatically initialize the Out object, so the use of the Out object is needed to refresh the page, and the Response.getwriter () response information through the Out object output to the Web page, when the response is closed automatically when the end of the Regardless of the JSP page, there is no need to refresh the page.

for a chestnut : When we call Response.getwriter () This object also obtains the brush of the Web page, then you can use this brush to draw anything you want to display on the Web page.

(4), Out of the print () method and the println () method will generate IOException when the buffer overflows and there is no automatic refresh, while the Response.getwrite () method's print and println are suppressed IO Exception exception, there will be no IO exception exception.

3, about the output expression <%=%>

(1), this is also about the output, and this expression of output compared to the above two, the only advantage is that the code can be divided into a clearer, but it is more troublesome to write.

Write () and print () also have <%=%> subtle differences

Related Article

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.