HttpServletResponse Output garbled problem

Source: Internet
Author: User

HttpServletResponse byte stream: Response.getoutputstream (). Write () Chinese garbled solution:
Notifies the browser in what encoding format to open the content Response.setheader ("Content-type", "Text/html;charset=utf-8") through the Content-type response header; String data = "China"; outputstream out = Response.getoutputstream ();//Before and after the format is unified, getBytes () does not specify the encoding format when using the platform default encoding format Out.write ( Data.getbytes ("UTF-8"));
Can write back <meta> tag to control browser parsing behavior
String data = "China"; outputstream out = Response.getoutputstream (); String meta = "<meta http-equiv= ' content-type ' content= ' Text/html;charset=utf-8 '/>": Out.write (Meta.getBtyes () ); Out.write (Data.getbytes ("UTF-8"));

Number garbled:

Through the Content-type response header, specify the response content format and the encoding format used Response.setheader ("Content-type", "text/html;charset=utf-8"); String data = "China"; outputstream out = Response.getoutputstream ();//output number: To first convert the number to a string and then GetBytes (), or the browser will be the original number by the specified code table to resolve the other content Without outputting the original digital Out.write ((3 + ""). Getbtyes ());
Character stream of HttpServletResponse: Response.getwriter (). Write ()
Specifies that the response is encoded in UTF-8 format response.setcharacterencoding ("UTF-8");//Notifies the browser what encoding format to open the content Response.setheader ("Content-type", " Text/html;charset=utf-8 ");//or Response.setcontenttype (" Text/html;charset=utf-8 "); String data = "China"; outputstream out = Response.getwriter (); out.write (data);


The Response.setcontenttype ("Text/html;charset=utf-8")//effect is equivalent to setcharacterencoding ("UTF-8") and SetHeader (" Content-type "," Text/html;charset=utf-8 ") Response.setcontenttype (" Text/html;charset=utf-8 "); String data = "China"; outputstream out = Response.getwriter (); out.write (data);



HttpServletResponse Output 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.