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