In asynchronous mode, when JSON is returned to the foreground, printwriter is used to output information to the foreground, but garbled characters occur during the output process.
So I remembered response. setcharacterencoding ("UTF-8"); sets the page encoding and response. setcontenttype ("text/html; charset = UTF-8"); sets the content type encoding. However, the encoding fails after the experiment and garbled characters remain unchanged.
PrintWriter out = response.getWriter(); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); out.print(json); out.flush(); out.close();
The returned JSON is as follows:
{"Seriesdata": [22619,22671, 21908,5415, 0], "caption": "Organization Code-Annual Statistics", "xaxisdata": ["2010 ", "January 2011", "January 2012", "January 2013", "January 2014"]}
After checking, it is found that printwriter will first get the project encoding and set characterencoding according to the encoding. Therefore, you must set the encoding before getting this printwriter object. Note the sequence as follows.
response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); PrintWriter out = response.getWriter(); out.print(json); out.flush(); out.close();