[英]Google app engine datastore string encoding problem
Hello I'm using Google App Engine for a project I'm doing and I need to store some Strings. 您好我正在使用Google App Engine进行我正在进行的项目,我需要存储一些字符串。 I'm using Java and JDOHelper.getPersistenceManagerFactory("transactions-optional")
我正在使用Java和JDOHelper.getPersistenceManagerFactory("transactions-optional")
While debugging it on my computer everything works fine and the Strings are saved correctly. 在我的计算机上进行调试时,一切正常,字符串正确保存。 But when i upload it to google app engine, all the Strings i save will have their unicode characters replaced by question marks (?). 但是当我将其上传到谷歌应用程序引擎时,我保存的所有字符串都会将其unicode字符替换为问号(?)。 If I go to the DataViewer on the project page, I can see that the Strings are actually saved with question marks. 如果我转到项目页面上的DataViewer,我可以看到字符串实际上是用问号保存的。
Like I said, when running it on my computer it works fine. 就像我说的,当在我的电脑上运行时,它运行正常。 Is there anyone who knows what I should do? 有谁知道我应该怎么做?
It sounds like you were not specifying the encoding for your HTTP POST content. 听起来您没有为HTTP POST内容指定编码。 Have a look at this question for details. 有关详细信息,请查看此问题 。
Like Jackrabbit said, you should specify charset. 就像Jackrabbit所说,你应该指定charset。 I still had some troubles on Google App Engine. 我仍然在Google App Engine上遇到了一些麻烦。 After setting charset to UTF-8 AND using Spring's CharacterEncodingFilter
nothing has bothered me encoding wise. 在将字符集设置为UTF-8并使用Spring的CharacterEncodingFilter
没有什么比编码方式困扰我了。
See How To Get Character Encoding Correct , which includes information on this code to add to your web.xml file: 请参见如何获取字符编码更正 ,其中包含有关要添加到web.xml文件的此代码的信息:
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Be sure to add this as the first step in your filter chain! 请务必将此添加为过滤器链中的第一步!
Also, the author of the blog suggests setting the charsets in your JSP pages to utf-8 as well: 此外,该博客的作者建议将JSP页面中的字符集设置为utf-8:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.