You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joel Rees <jo...@alpsgiken.gr.jp> on 2002/03/01 07:31:49 UTC

Re: changing the default character encoding

Java news groups archives can be accessed at

http://groups.google.com/groups?group=comp.lang.java

but see below:

Richard Sand asked:

> Hi all,
>
> I am still beating my head against a brick wall trying to get the default
> encoding changed for my Tomcat server on Linux (slackware 2.4.17 if it
> matters).
>
> The problem is actually outside of Tomcat so please excuse the slightly
> off-topic question.  But basically, I've run the following simple test:
>
> import java.io.InputStreamReader;
> import java.io.ByteArrayInputStream;
> public class Encoding {
>   public static void main(String[] args){
>     byte[] bytes = new byte[0];

Mind if I ask why you have a 0 byte buffer here? (Although perhaps it
wouldn't matter for what you're testing.)

>     ByteArrayInputStream bs = new ByteArrayInputStream(bytes);
>     InputStreamReader in = new InputStreamReader(bs);

I tried this:

      InputStreamReader in = new InputStreamReader(bs, "US-ASCII");

(Shift_JIS is the usual for me.) I had to declare the main method as "throws
UnsupportedEncodingException" to get it to compile, but the responded with
the changed encoding when run from the command line.

So it looks like it might be a Tomcat question? But I think I recall seeing
some answer on the list or in the docs. It may come down to having to
declare the encoding from your web pages, or read it from the headers the
browser sends or something.

Not much help, I suppose.

Joel Rees

>     System.out.println("file.encoding is " +
> System.getProperty("file.encoding"));
>     System.out.println("default encoding is " + in.getEncoding());
>   }
> }
>
> And no matter what I try, it always says "default encoding is ASCII", no
> matter what I've specified file.encoding as.  I'm invoking the class as:
>
> java -cp $CLASSPATH:. -Dfile.encoding=ISO8859_1 Encoding
>
> I've tried the following values for file.encoding with no changes:
>
> ISO8859_1
> ISO-8859-1
> 8859_1
> iso-8859-1
> iso8859-1
> iso8859_1
> en_US
> no_NO
> norwegian
>
> I've also tried every one of those values for LANG and LC_ALL in my
> environment variables.
>
> Please, someone help me! How do I change the damned default encoding????
> Why isn't it picking up on my environment variables or the file.encoding
> property? Running "java -version" tells me:
>
> java version "1.3.1_02"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
> Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)
>
> Can anyone help? I'm totally stymied here!
>
> Best regards,
>
> Richard




--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>