Javaweb's response response to Chinese garbled problem

Source: Internet
Author: User

Response to page in response to Chinese garbled problem

Byte stream

* may be garbled, with Chinese converted to byte array, browser open default character encoding about

* Workaround: Use the same character set when you turn Chinese into byte arrays and the browser opens by default

Response.setheader ("Content-type", "Text/html;charset=utf-8"); Response.getoutputstream (). Write ("Zhang San". GetBytes ("Utf-8"));

Character Stream

* must be garbled, because The default encoding for the response character buffer is iso-8859-1

* Workaround: Set response to get the encoding of the character stream buffer and set the character set that the browser uses when it is opened by default

// Set Browser default open character set response.setheader ("Content-type", "Text/html;charset=utf-8"); // sets the character stream buffer encoding response.setcharacterencoding ("Utf-8"); Response.getwriter (). println ("Zhang San") ;
* use character flow to page response there is a simplified notation
Response.setcontenttype ("Text/html;charset=utf-8"); Response.getwriter (). println ("Zhang San");

Javaweb's response response to Chinese garbled problem

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.