sc wrote:
There is an earlier post
http://mail-archives.apache.org/mod_mbox/struts-user/200603.mbox/[EMAIL PROTECTED]
My problem is pretty much the same as described. But there is no soluton to
it.
My application is Tomcat + Struts.
In the struts action class, I generates a WordML xml and the browser starts
a word. The word document may contain Chinese character. My source code is
something like:
response.setContentType("application/msword; charset=UTF-8");
java.io.PrintWriter out = response.getWriter();
out.println(outLine);
out.close();
outLine is a big string, with the first 2 lines as the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
Now the weird thing is when I run this on my desktop, with Chinese Windows
XP installed. Everything is fine. But when I run this on a production server
with English version Windows 2003 installed, all chinese characters are
displayed as ??.
After I changed the code to:
response.setContentType("text/xml; charset=UTF-8");
regardless of where I run the application, it can correctly display chinese
characters, though in a text version.
It sounds like you've answered your own question. Your first code
fragment writes out an XML document that declares its character encoding
as UTF-8, but you don't have any code to ensure the response uses that
encoding.
Calling setContentType() is only part of the correct solution, though.
You should also call setCharacterEncoding() on the response.
setContentType() helps the user agent (browser, etc.) to figure out what
character encoding it should assume is in use; setCharacterEncoding()
ensures that a particular encoding *is* used. The 'encoding' attribute
in your XML declaration must then match that encoding.
HTH,
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]