On 4/28/07, red phoenix <[EMAIL PROTECTED]> wrote:
when ajax receive information which include Chinese code from action of
Struts2,ajax will show chinese code into confusion code,but if ajax receive
information which include Chinese code from jsp, ajax will show correct
Chinese code.I don't know why raise this error! How to correct it?
response.setContentType("text/html;charset=gb2312");
You set the charset to gb2312...
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pargma","no-cache");
(Note: that should read "Pragma", not "Pargma".)
StringBuffer sb=new StringBuffer("<state>");
sb.append
("<city>北京</city><city>yangzhou</city><city>suzhou</city>");
sb.append("</state>");
PrintWriter out=response.getWriter();
out.write(sb.toString());
But you don't send gb2312 bytes back to the client. Java strings are
Unicode (internally, UTF-16be), and when you convert them to bytes
without specifying what encoding to use, you get the "default platform
encoding", which could be just about anything, depending on what
platform you are on, the JVM and appserver you are using, the version,
the phase of the moon, etc.
If you want to convert the string to gb2312 bytes, you need to convert
the string to gb2312 bytes.
out.write(sb.toString().getBytes("gb2312"));
N.B. this can throw an UnsupportedEncodingException, in theory,
although it shouldn't for well-known encodings, in practice.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]