Google App Engine Java runtime的file.encoding居然不是UTF-8
Google App Engine支持Java了,下午在Windows下测试Google App Engine Java Servlet的中文是正常的,但是测试的jsp页面显示却是乱码,
参考:http://618119.com/archives/2009/04/08/145.html
于是晚上写了下面的代码来取出系统属性和环境变量来看:
[code]
out.println("系统属性有:《br/》");
Enumeration e1 = System.getProperties().propertyNames();
String s1 = "";
while (e1.hasMoreElements()) {
String key = (String) e1.nextElement();
String value = System.getProperty(key);
out.println(key + "=" + value + "《br/》");
}
out.println("系统环境变量有:《br/》");
for (Map.Entry《String, String》 et : System.getenv().entrySet()) {
out.println(et.getKey() + "=" + et.getValue() + "《br/》");
}
out.println("你的请求属性有以下内容:《br/》");
Enumeration e2 = req.getAttributeNames();
while (e2.hasMoreElements()) {
String key = (String) e2.nextElement();
Object value = req.getAttribute(key);
out.println(key + "=" + value + "《br/》");
}
out.println("你的请求头信息有以下内容:《br/》");
Enumeration e = req.getHeaderNames();
String s = "";
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = req.getHeader(key);
out.println(key + "=" + value + "《br/》");
}
[/code]
程序运行结果如下:
系统属性有:
java.vendor=Sun Microsystems Inc.
java.specification.version=1.6
line.separator=
java.class.version=50.0
java.util.logging.config.file=WEB-INF/logging.properties
java.specification.name=Java Platform API Specification
java.vendor.url=http://java.sun.com/
java.vm.version=1.6.0_13
os.name=Linux
java.version=1.6.0_13
java.vm.specification.version=1.0
user.dir=/base/data/home/apps/lizongbo/2.332646483357654537
java.vm.specification.name=Java Virtual Machine Specification
java.specification.vendor=Sun Microsystems Inc.
java.vm.vendor=Sun Microsystems Inc.
file.separator=/
path.separator=:
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.vendor=Sun Microsystems Inc.
file.encoding=ANSI_X3.4-1968
系统环境变量有:
你的请求属性有以下内容:
com.google.apphosting.runtime.jetty.APP_VERSION_REQUEST_ATTR=lizongbo/2.332646786822574367
你的请求头信息有以下内容:
Host=lizongbo.appspot.com
User-Agent=Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.0.8) Gecko/2009032712 Ubuntu/8.10 (intrepid) Firefox/3.0.8,gzip(gfe)
Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language=zh-cn,zh;q=0.5
Accept-Charset=gb2312,utf-8;q=0.7,*;q=0.7
其中很奇特的是Google App Engine Java runtime的file.encoding=ANSI_X3.4-1968,而不是UTF-8。
从request的属性里看到了jetty字样,,不知google App Engine 的java运行环境是否和jetty有什么关系。
在Ubuntu下Eclipse里重新建立testweb,重新建立test.jsp,这次传上去再访问,中文显示就正常了。 测试地址:http://lizongbo.appspot.com/test.jsp
不明白是何原因。
Tags: encoding, Google App Engine, Java