Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I'm using Java and 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 (?). If I go to the DataViewer on the project page, I can see that the Strings are actually saved with question marks.

Like I said, when running it on my computer it works fine. Is there anyone who knows what I should do?

like image 968
Joel Avatar asked Mar 26 '11 22:03

Joel


2 Answers

It sounds like you were not specifying the encoding for your HTTP POST content. Have a look at this question for details.

like image 56
jackrabbit Avatar answered Oct 27 '22 02:10

jackrabbit


Like Jackrabbit said, you should specify charset. I still had some troubles on Google App Engine. After setting charset to UTF-8 AND using Spring's CharacterEncodingFilter nothing has bothered me encoding wise.

See How To Get Character Encoding Correct, which includes information on this code to add to your web.xml file:

<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:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
like image 42
Johan Norén Avatar answered Oct 27 '22 00:10

Johan Norén