Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.
(Answer) (Category) Java Apache Project : (Category) Apache JServ 1.0 : (Category) Programming and Misc. Tidbits :
How to correctly do character encoding...this example is for Korean, but will apply to other as well...
----------
From: Martin Kuba makub@inet.cz
To: Java Apache Users java-apache-users@list.working-dogs.com
Subject: Re: Character encoding..
Date: Mon, 13 Sep 1999 13:40:14 +0200

mskang wrote:
> 
> i have had many problems to display Korean-characters with java.
> 
> "i should use"
> 
> out = new PrintWriter(new OutputStreamWriter(new
> FileOutputStream(filename,true),"KSC5601")); // write to a file (KSC5601
> is character encoding for Korean)
> 
> "instead using"
> 
> out = new BufferedWriter(new FileWriter(filename,true));
> 
> "to correctly display our language."
> 
> when i looked api reference for FileWriter class,
> 
> "The constructors of this class assume that the default character
> encoding and the default byte-buffer size are acceptable. To specify
> these values yourself, construct an OutputStreamWriter on a
> FileOutputStream."
> 
> where can i set default character encoding ? not specify everytime i use
> it !! anybody knows it ?
> 
> --mskang

You do it wrong. When you want to send Korean text
to browser from Java servlet, do it as follows:

--------------------------------------------------------------
public void service (HttpServletRequest request,
                      HttpServletResponse response) 
                   throws ServletException, IOException
 {
   PrintWriter out;
   response.setContentType("text/html; charset=KSC5601");
   out = response.getWriter();
   try {
   //add code here   
    out.println("...");
   //-----        
   } catch (Exception ex) {out.println(ex.getMessage());ex.printStackTrace(out);}
 }
--------------------------------------------------------------

If you want to write to files, do it as follows:
--------------------------------------------------------------
PrintWriter out
 = new PrintWriter(
    new OutputStreamWriter(
     new FileOutputStream("koreanfile.txt"),"KSC5601"));
out.println("...");
--------------------------------------------------------------

If you want to use Korean encoding as default, you have to specify
it to your JVM. In WindowsNT, use "Regional settings", in UNIX,
use "LC_ALL=ko_KR java MyClass" for starting JVM.

Hope this helps

Martin
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   INET, a.s.                          Mgr. Martin Kuba
Kralovopolska 139                  e-mail: makub@inet.cz
  601 12 Brno                      WWW: http://www.inet.cz/~makub/
 Czech Republic                    tel: +420-5-41242414/33
--------------------------------------------------------------------
PGP fingerprint = D8 57 47 E5 36 D2 C1 A1  C3 48 B2 59 00 58 42 27
 http://wwwkeys.cz.pgp.net:11371/pks/lookup?op=index&search=makub
--------------------------------------------------------------------
----------
From: "Pawel Pesz" pawp@insert.com.pl
To: "Java Apache Users" java-apache-users@list.working-dogs.com
Subject: Re: Character encoding..
Date: Mon, 13 Sep 1999 14:29:33 +0200

mskang mskang@Helper.chunwoo.co.kr wrote:
>> where can i set default character encoding ? not specify
>> everytime i use it !! anybody knows it ?

Martin Kuba makub@inet.cz wrote:
> If you want to use Korean encoding as default, you have to
> specify it to your JVM. In WindowsNT, use "Regional
> settings", in UNIX, use "LC_ALL=ko_KR java MyClass" for
> starting JVM.

You can also set the "file.encoding" property. Add the
following to your "jserv.properties":

wrapper.bin.parameters=-Dfile.encoding=<your encoding>

It may be also useful to specify your default locale and
timezone:

wrapper.bin.parameters=-Duser.language=<your language> -Duser.region=<your country>
wrapper.bin.parameters=-Duser.timezone=<your timezone>

Best regards :-)

--
Pawel Pesz
InsERT.net, Wroclaw, Poland
webmasterATinsertDOTnetDOTpl
http://www.insert.net.pl
----------
From: Martin Kuba makub@inet.cz
To: Java Apache Users java-apache-users@list.working-dogs.com
Subject: Re: Character encoding..
Date: Mon, 13 Sep 1999 16:03:40 +0200

Pawel Pesz wrote:
> 
> You can also set the "file.encoding" property. Add the
> following to your "jserv.properties":
> 
> wrapper.bin.parameters=-Dfile.encoding=<your encoding>

No, file.encoding property should not be set from
the command line.
See the "evaluation" part of bug in
http://developer.java.sun.com/developer/bugParade/bugs/4256423.html

Martin
[Append to This Answer]
Previous: (Answer) need a sample servlet that process "multipart/form-data"
Next: (Answer) New Item
This document is: http://java.apache.org/faq/?file=293
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.709.
Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.