Change Tomcat's Charset.defaultCharset in windows

谁都会走 提交于 2019-11-26 22:53:57

问题


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


回答1:


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

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



回答2:


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

from Dr James Bayley's blog




回答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.




回答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



来源:https://stackoverflow.com/questions/11342884/change-tomcats-charset-defaultcharset-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!