IDependOn-Set: 1
IDependOn-Set: 119
IDependOn-Set: 2
IDependOn-Set: 292
IDependOn-Set: 293
IDependOn-Set: 305
LastModifiedSecs: 937247051
Parent: 119
SequenceNumber: 4
Title: How to correctly do character encoding...this example is for Korean, but will apply to other as well...
Part: 0
Author-Set: jon@working-dogs.com
HideAttributions: 1
LastModifiedSecs: 937246758
Type: monospaced
Lines: 79
----------
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
--------------------------------------------------------------------
EndPart: 0
Part: 1
Author-Set: jon@working-dogs.com
HideAttributions: 1
LastModifiedSecs: 937246810
Type: monospaced
Lines: 34
----------
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
mailto:webmaster@insert.net.pl
http://www.insert.net.pl
EndPart: 1
Part: 2
Author-Set: jon@working-dogs.com
HideAttributions: 1
LastModifiedSecs: 937247051
Type: monospaced
Lines: 19
----------
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
EndPart: 2
