4

I'm using Java. This is the pure data that gets inserted in the datastore:

<p>Something</p>\n<p>That</p>\n<p> </p>\n<p>Should.</p>\n<p> </p>\n
<p>I have an interesting question.</p>\n<p>Why are you like this?</p>\n
<p> </p>\n<p>Aren't you fine?</p>

This is how it gets stored:

<p>Something</p> <p>That</p> <p>�</p> <p>Should.</p> <p>�</p> 
<p>I have an interesting question.</p> <p>Why are you like this?</p> 
<p>�</p> <p>Aren't you fine?</p>

What's up with the weird symbols? This happens only live, not on my local dev_appserver.

EDIT

Here's the code that inserts the data:

String content = ""; // this is where the data is stored
try {
    ServletFileUpload upload = new ServletFileUpload();
    FileItemIterator iter = upload.getItemIterator(request);
    while(iter.hasNext()) {
        FileItemStream item = iter.next();
        InputStream stream = item.openStream();

        if(item.isFormField()) {
            String fieldName = item.getFieldName();
            String fieldValue = new String(IOUtils.toByteArray(stream), "utf-8");
            LOG.info("Got a form field: " +fieldName+" with value: "+fieldValue);
            // assigning the value
            if(fieldName.equals("content")) content = fieldValue;
        } else {
            ...
        }
    }
} catch (FileUploadException e){
}

...
// insert it in datastore
Recipe recipe = new Recipe(user.getKey(), title, new Text(content), new Text(ingredients), tagsAsStrings);
pm.makePersistent(recipe);

It's a multipart/form-data form so I have to do that little item.isFormField() magic to get the actual content, and construct a String. Maybe that's causing the weird encoding issue? Not sure.

To retrieve the data I simply do:

<%=recipe.getContent().getValue()%>

Since content is of type Text (app engine type) I use the .getValue() to get the actual result. I don't think it's an issue with retrieving the data, since I can see the weird characters directly in the online app-engine datastore viewer.

Luca Matteis
  • 29,161
  • 19
  • 114
  • 169

2 Answers2

0

Are you using eclipse ? if yes check under File > Properties > Text File encoding that your file is UTF-8 encoding.

I would guess not.

So, change it to UTF-8 and your issue should get fixed.

regards

didier

Didier Durand
  • 627
  • 7
  • 16
0

Followed this page to create a Servlet Filter so that all my pages were being encoded in utf8:

How to get UTF-8 working in Java webapps?

After creating the filter, everything works!

Community
  • 1
  • 1
Luca Matteis
  • 29,161
  • 19
  • 114
  • 169