PDA

View Full Version : Chinese UTF8 characters problems in Quercus


stevencage
10-22-2011, 10:35 AM
Hello I'm new to Quercus,recently we are trying to integrate java with php in our project and we met Chinese UTF8 characters problems in Quercus.

All files(.php,.java)are encoded in UTF-8.Resin version 4.0.23.Quercus version 4.0.18.
test.php

<?php
echo "Chinese中文<br/>";
?>


Chinese涓枃
The Chinese characters are garbled :eek:and the page are encoded by gbk...

Then I try configure resin.xml and set character-encoding to utf-8
<web-app-default>
<character-encoding>UTF-8</character-encoding>
...
</web-app-default>
It works,the Chinese characters display correctly!;)
Chinese中文
and the page are encoded by utf-8:cool:

Then I try to call java method in php~

edit test.php

<?php
$demoService = spring_bean("demoServiceImpl");
$str=$demoService-> test("中文");
echo "中文:str from java:";
echo $str;
?>

java method:

public String test(String str){
System.out.println("str from php:"+str);
return "中文";
}


The Chinese characters are ???? in java console #_#
Then I editresin-web.xml

<web-app xmlns="http://caucho.com/ns/resin">
<servlet-mapping url-pattern="*.php"
servlet-class="com.caucho.quercus.servlet.QuercusServlet">
<init>
<script-encoding>utf-8</script-encoding>
</init>
</servlet-mapping>
</web-app>

in java console,it's ok!
str from php:中文
But in web browser are still garbled
-?str from java:-?
Any suggestions?

westleo
01-05-2012, 07:02 AM
Or you can re-encode in java

String strInJava = new String(strFromPhp.getBytes("iso8859-1"), "utf-8");