When I use django, I write a method can be invoked by http:// myhost/XXX/testIndex
def testIndex(request):
res = os.system('java -jar test.HelloWorld' > /tmp/log)
... ...
and the HelloWorld java is as follows:
public class HelloWorld {
public static void main(String[] args) throws IOException {
System.out.println("hello!");
System.out.println("你好!");
}
When I access the http:// myhost/XXX/testIndex, the result is when I open the /tmp/log file, the UTF-8 chars is not correct!
like this
hello! ??!
What happened ? BTW, I am under linux centOS
You have two problems:
You have put non-ASCII characters in your Java source. This is not generally considered good practice, because you will need to tell the Java compiler what encoding you have used for the source file. If it’s UTF-8, try:
javac -encoding UTF-8 HelloWorld.java.The default encoding for System.out may not be UTF-8. It would help if you said which JRE you are using, as different implementations may behave slightly differently. You may be able specify the encoding explicitly with
java -Dfile.encoding=UTF-8, although this is also not recommended. If it’s the Sun or OpenJDK JRE, you need to set the LANG environment variable before Java starts; you might do this in your webserver configuration, or by using thesubprocesspython module which allows you to specify the environment passed to the new process.