Reputation: 13444
I have a script that output some XML containing UTF-8 characters. It works well with latin languages (éàœ,...) but fail when I enter arabic characters: The output is truncated at the first arabic character (ضصيضص).
My code looks like that:
public void doGet(HttpServletRequest req, HttpServletResponse res) {
//...
res.setCharacterEncoding("UTF-8");
res.setContentType("text/xml; charset=utf-8");
String xml = getXMLString();
LOG.debug(xml); // Output is correct here
op.print(xml);
op.flush();
op.close();
}
Also, it appears correctly when I display it as HTML
Upvotes: 1
Views: 696
Reputation: 3475
Instead of HttpServletOutputStream
(for binary data), use PrintWriter
getWriter of ServletResponse
that can send character string to client.
res.setCharacterEncoding("UTF-8");
res.setContentType("text/xml; charset=utf-8");
PrintWriter writer = res.getWriter();
//now write your text
Upvotes: 4