(Java) app engine in web application use out.println("测试") and print messy code ,(后台打印中文信息乱码)

63 views
Skip to first unread message

Haitao Zhang

unread,
Sep 24, 2013, 4:57:08 AM9/24/13
to google-a...@googlegroups.com
i was a new user for engine web application
After deploy my web application project to app engine,use out.println("测试") print  messy code . 

1.i test project in window eclispe , and it can print correct chinese , but when deploy to app engine, the log print messy code(like ??????--???)
2.another question was when i fetch info from some china website, is also print messy code 

i search  that question whereever ,but nobody question like that, it let me feel helpness,
can someone tell me how to fix that situation?





Vinny P

unread,
Sep 25, 2013, 10:08:01 AM9/25/13
to google-a...@googlegroups.com
On Tue, Sep 24, 2013 at 3:57 AM, Haitao Zhang <seati...@gmail.com> wrote:
i was a new user for engine web application
After deploy my web application project to app engine,use out.println("测试") print  messy code . 

1.i test project in window eclispe , and it can print correct chinese , but when deploy to app engine, the log print messy code(like ??????--???)


The actual logs are still there, but the charset/encoding is different from what App Engine is expecting so you get those question marks and characters that look like boxes. See here for an example: 

If you use Chrome, try this page and see if it helps: http://productforums.google.com/forum/#!topic/chrome/EfrrDYQ1-_g



On Tue, Sep 24, 2013 at 3:57 AM, Haitao Zhang <seati...@gmail.com> wrote:
2.another question was when i fetch info from some china website, is also print messy code 



Is the urlfetch itself corrupted or the printing into logs damaged? Make sure you're encoding/decoding in UTF-8.

 
-----------------
-Vinny P
Technology & Media Advisor
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com
 

Haitao Zhang

unread,
Sep 25, 2013, 10:34:01 PM9/25/13
to google-a...@googlegroups.com
: ) thanks, that give me a way to find the answer. so i change the charset in app engine many many times. but still unsolve. so i change the server ,hahah 
i found some idea in chinese , so list here:
//-------------------------------------------------------------
最终的class文件都是以unicode编码的,我们前面所做的工作就是把各种不同的编码转换为unicode编码,比如从GBK转换为unicode,从UTF-8转换为unicode。因为只有采用正确的编码来转码才能保证不出现乱码。Jvm在运行时其内部都是采用unicode编码的,其实在输出时,又会做一次编码的转换。让我们分两种情况来讨论。
1.java中采用Sysout.out.println输出。
比如:Sysout.out.println(“我们”)。经过正确的解码后”我们”是unicode保存在内存中的,但是在向标准输出(控制台)输出时,jvm又做了一次转码,它会采用操作系统默认编码(中文操作系统是GBK),将内存中的unicode编码转换为GBK编码,然后输出到控制台。因为我们操作系统是中文系统,所以往终端显示设备上打印字符时使用的也是GBK编码。因为终端的编码无法手动改变,所以这个过程对我们来说是透明的,只要编译时能正确转码,最终的输出都将是正确的,不会出现乱码。在Eclipse中可以设置控制台的字符编码,具体位置在Run Configuration对话框的Common标签里,我们可以试着设置为UTF-8,此时的输出就是乱码了。因为输出时是采用GBK编码的,而显示却是使用UTF-8,编码不同,所以出现乱码。
//-------------------------------------------------------------
i used that method to print the app engine system params
System.getProperties().list(System.out); 
and i found app engine charset was "ANSI_X3.4-1968"
so i set system-properties params to change the charset in appengine-web.xml ,like :
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties" />
<property name="file.encoding" value="utf-8" />
<property name="default.client.encoding" value="gbk" />
<property name="sun.jnu.encoding" value="gbk" />
<property name="sun.io.unicode.encoding" value="gbk" />
<property name="user.language" value="en_US.gbk" />
</system-properties>
it can change the charset in app engine,but after i test many many times it was still failure. 
anyway i think that should be the correct way to solve that question
Reply all
Reply to author
Forward
0 new messages