HttpServletResponse output of Chinese characters

Source: Internet
Author: User

HttpServletResponse output has two formats, one is a character stream, and the other is byte flow.

1. Character Stream

// The meaning of this sentence is to let the browser use UTF8 to parse the returned data, that is, to set the encoding        of client parsing Response.setcontenttype ("text/html; Chartset=utf-8 ");         //         response.setcharacterencoding ("UTF-8");         = Response.getwriter ();        Printwriter.print ("Chinese");

2. Byte stream

The meaning of this sentence is to let the browser use UTF8 to parse the returned data, that is, set the client to parse the encoding        response.setheader ("Content-type", "Text/html;charset=utf-8");         // Response.setcontenttype ("text/html; Chartset=utf-8 ");  Try to use this setting "Content-type" not successful        String data = "Chinese"        ; = Response.getoutputstream ();         // The meaning of this sentence, so that the data is UTF8 format        Ps.write (Data.getbytes ("Utf-8"));

Reference:

http://blog.csdn.net/kontrol/article/details/7767983

HttpServletResponse output of Chinese characters

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.