Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Tomcat's Charset.defaultCharset in windows

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

like image 375
nonouco Avatar asked Jul 05 '12 10:07

nonouco


3 Answers

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

set "JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF8"
like image 149
nonouco Avatar answered Nov 19 '22 00:11

nonouco


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

screenshot

from Dr James Bayley's blog

like image 40
James Bayley Avatar answered Nov 19 '22 00:11

James Bayley


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.

like image 6
lpi314 Avatar answered Nov 19 '22 00:11

lpi314