You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Wyn Easton <wy...@yahoo.com> on 2001/06/01 21:36:03 UTC

Internationalization

After a bunch of trial and error and some help from
Jason Hunter's NEW Servlet Programming (2nd Edition)
Book we finally got our JSPs and Servlets to support
foreign languages.

I'm going to put what we did in this note for anybody
else that may need to do this and ask a related
question at the end.

First, we added the following to the JSPs:

<%@ page
contentType="text/html;charset=UTF-8"            
%>

We also added the following to the HTML header in each
JSP:

<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">

It seems that the JSP page directive will get you an
"out" (a JspWriter) that will ouput UTF-8 encoded
characters.  This is needed for everthing that is
translated on the page like labels and headings.
(Our property files have been translate into the
different languages we need and we get the labels and
headings from these files)

The meta tag controls the way the browser returns the
data for the forms we have in our JSPs.

That is all we had to do for the JSPs.

In the Servlets that process the Form data we did the
little trick from Jason's book:

String input = request.getParameter("firstName");
input=new String(input.getBytes("ISO-8859-1","UTF-8");

Now "input" is a String encoded in UTF-8.

If we used this String as the VALUE of an INPUT tag
before we converted it to UTF-8, the JspWriter would
convert it to UTF-8 not knowing that it was already
UTF-8 and expand the String.

<input type="text" name="firstname"
value="<%=input%>">

My question is,  is there a Java setting or maybe a
Tomcat setting that will use UTF-8 as the default for
String objects?  I'm not so sure that even if we did
default Java to UTF-8 that we would have a better
soultion because not everything we read is UTF-8
encoded.

Hope this helps and
thanks for any ideas.



















__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/