【发布时间】:2011-08-08 02:44:24
【问题描述】:
我正在使用 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() 的小魔法来获取实际内容并构造一个字符串。也许这导致了奇怪的编码问题?不确定。
要检索数据,我只需这样做:
<%=recipe.getContent().getValue()%>
由于content 是文本类型(应用程序引擎类型),我使用.getValue() 来获得实际结果。我认为检索数据不是问题,因为我可以直接在在线应用引擎数据存储查看器中看到奇怪的字符。
【问题讨论】:
-
\n 是新行的指示符。你指的是这个吗?
-
这是 99% 的编码问题;您如何处理代码中的编码?你能发布一些相关的sn-p吗?
-
@systempuntoout:我不处理它。我有什么特别的需要去做吗?
-
你怎么知道它是这样存储的?你在哪里读这个?数据存储查看器还是 Jsp?
-
@systempuntoout:我在此处显示的内容直接来自数据存储查看器。 JSP 只显示一个普通的问号符号。
标签: java google-app-engine jdo