I have looked at your document and think that I am doing everything
according
to the document mentioned. To eliminate the possibility of an
incompatible
ResourceBundle and to test input in UTF-8, I wrote two more test
programs.
The first uses Unicode escape characters to write out the labels to a
properties
file. This actually fixed the label problem whether or not I use
response.getWriter()
or response.getOutputStream.
However, I wrote some additional code to get input from the user and I
enter the
input in Chinese using Nanjixing. The input is read by my servlet,
below, and
echoed back in the post method. Even though the labels from the
resource bundle
and the string literals in UTF-8 are now shown correctly, the input from
the
user is garbled.
Can anyone how has previously done internationalization of a web user
interface
in UTF-8 throw any light on this?
Servlet code is below. I have output both using an xsl translation and
direct
from the Writer and both are garbled.
public class I18NForm extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
out.print("<form method='POST'>");
out.print("Input: <input name='userid'><p>");
out.print("<INPUT type='submit' value='Send'>");
out.print("<form>");
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
Locale locale = new Locale("zh", "CN");
ResourceBundle bundle = ResourceBundle.getBundle("UTF8",
locale);
String logon = "\u767b\u5165";
String logonLabel = bundle.getString("logon");
String country = "\u56fd\u5bb6";
String countryLabel = bundle.getString("country");
String china =
"\u4e2d\u534e\u4eba\u6c11\u5171\u5171\u548c\u56fd";
String chinaLabel = bundle.getString("china");
String input = request.getParameter("userid");
String xml = "<?xml version='1.0\' encoding='utf-8'?><test>" +
logon + ": " + logonLabel + "<br/>" +
country + ": " + countryLabel + "<br/>" +
china + ": " + chinaLabel + "<br/>" +
"input: " + request.getParameter("userid") + "<br/>" +
"</test>";
//PrintWriter out = response.getWriter();
ServletOutputStream out = response.getOutputStream();
out.print("<br/>input: " + request.getParameter("userid") +
"<br/>");
render(response, xml);
out.close();
}
/** Render an xml document into html
*/
private void render(HttpServletResponse res, String xml) throws
IOException,
ServletException {
try {
XSLTProcessor processor =
XSLTProcessorFactory.getProcessor();
Reader stringReader = new StringReader(xml);
XSLTInputSource xmlSource = new
XSLTInputSource(stringReader);
String xslFN =
StyleSheetLocator.getStyleSheetURI("template.xsl");
XSLTInputSource xslSource = new XSLTInputSource(xslFN);
XSLTResultTarget target = new
XSLTResultTarget(res.getWriter());
processor.process(xmlSource, xslSource, target);
} catch(SAXException e) {
e.printStackTrace();
}
}
}
-----Original Message-----
From: Praveen Tapashetti [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 08, 2001 8:45 PM
To: [EMAIL PROTECTED]
Subject: Re: web site internationalization
Hi,
There are some things to be done like setting charset for chinese
characters
in html,
And in servlet, setting contentType charset="the charset that supports
chinese".
I have documented all these.
Refer to it. I am sending to ur personal-id.
Regards
Praveen Tapashetti
Mascot Systems Ltd
Chennai, India
Tel: 91-44-2301236 Extn: 3321
-----Original Message-----
From: Alex Amies [SMTP:[EMAIL PROTECTED]]
Sent: Friday, March 09, 2001 7:13 AM
To: [EMAIL PROTECTED]
Subject: web site internationalization
I have a problem manipulating utf-8 strings in servlets. The
output
appears garbled. For example, the servlet below should show a
page
with the Chinese translation for 'logon', consisting of the two
characters ? (u\767b, deng) ? (u\5165, ru), but the result is
garbled:
public void service(HttpServletRequest request,
HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
//PrintWriter out = response.getWriter();
ServletOutputStream out = response.getOutputStream();
out.println("\u767b\u5165");
Locale locale = new Locale("zh", "CN");
ResourceBundle bundle = ResourceBundle.getBundle("UTF8",
locale);
String country = bundle.getString("country");
out.println(country);
out.close();
}
The String 'country' (??) is looked up from a resource bundle
and
printed correctly
in Chinese after it but not on the next line . What's up here?
The interesting thing is this: When I switch the
response.getOutputStream() line
with the commented out line response.getWriter() the opposite
happens.
'Logon' is
now printed correctly and 'country' is garbled. Interesting.
The frustrating point is this: I am using xslt to translate xml
to
html
and the
whole lot seems to be garbled, whichever I use. I am using
Apache
Xalan. The
same code will work if writing to a file from a stand-along app
instead
of from
a servlet to a browser.
Alex Amies
________________________________________________________________________
___
To unsubscribe, send email to [EMAIL PROTECTED] and include
in
the body
of the message "signoff SERVLET-INTEREST".
Archives:
http://archives.java.sun.com/archives/servlet-interest.html
Resources:
http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
________________________________________________________________________
___
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html