我正在使用Java。这是插入到数据存储区中的纯数据:

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

它是这样存储的:
<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>

奇怪的符号怎么了?这种情况仅实时发生,而不是在本地dev_appserver上发生。

编辑

这是插入数据的代码:
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);

这是一种multipart/form-data形式,所以我必须做一点item.isFormField()魔术才能获取实际内容,并构造一个String。也许这导致了奇怪的编码问题?不确定。

要检索数据,我只需执行以下操作:
<%=recipe.getContent().getValue()%>

由于content的类型为文本(应用引擎类型),因此我使用.getValue()来获取实际结果。我认为检索数据不是问题,因为我可以直接在在线应用程序引擎数据存储查看器中看到奇怪的字符。

最佳答案

您正在使用Eclipse吗?如果是,请在文件>属性>文本文件编码下检查您的文件是UTF-8编码。

我猜不会。

因此,将其更改为UTF-8即可解决您的问题。

问候

迪迪埃

09-26 19:59
查看更多