Change Tomcat's Charset.defaultCharset in windows

42,416

Solution 1

Just create a setenv.bat file inside the TOMCAT/bin directory with the following contents:

set "JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF8"

Solution 2

You may also add this setting in the Tomcat 7.0 windows service manager.

screenshot

from Dr James Bayley's blog

Solution 3

For Tomcat running as a Windows service neither %JAVA_OPTS% and neither setenv.bat answers works in my case.

I set the option "-Dfile.encoding=UTF8" in registry:

"HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\tomcatstackTomcat\Parameters\Java --> Options*

Then it works.

Solution 4

Try setting the (Windows) environment variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8 and start the Tomcat Server.

Will get more idea from this link: Setting the default Java character encoding

Share:
42,416
nonouco
Author by

nonouco

Updated on July 05, 2022

Comments

  • nonouco
    nonouco almost 2 years

    I'm using tomcat 6.0.32 in windows 7. Inside a very simple servlet, inside the init method, I'm printing:

    System.out.println(Charset.defaultCharset());
    

    The output is:

    windows-1253
    

    As far as I understand this is how tomcat start's in the JVM since I'm printing the same in standalone java class and I get "UTF8" as a response.

    So, how can I change this to UTF-8?

    thanks

  • nonouco
    nonouco almost 12 years
    Unfortunately this is not working. Setting -Dfile.encoding=UTF-8 is the correct approach but I don't thin that tomcat is appending JAVA_TOOL_OPTIONS to JAVA_OPTS. In any case I found the solution. Check below.
  • Marco Altieri
    Marco Altieri over 8 years
    Is the correct configuration -Dfile.encoding=UTF-8 or -Dfile.encoding=UTF8? I think that it should be UTF-8
  • nonouco
    nonouco over 8 years
    The correct is as described in the answer, i.e. UTF8 - check these two: 1) stackoverflow.com/questions/6031877/… 2)docs.oracle.com/javase/6/docs/technotes/guides/intl/…
  • Yogesh Bombe
    Yogesh Bombe about 5 years
    This setting works for me.I have one more question is this setting requires only in windows os or we need to define this in linux also?