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