2011-04-18 2 views
4

자바를 사용하고 있습니다.Google App Engine - 이상한 방식으로 데이터 저장 중

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

이 이상한 기호까지 무엇 : 이것은이 저장되는 방식이다

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

:이 데이터 저장소에 삽입됩니다 순수한 데이터입니까? 이것은 로컬 dev_appserver가 아닌 라이브에서만 발생합니다. 나는 작은 item.isFormField() 마법 실제 내용을 얻기 위해 그렇게하고, 문자열을 구성 할 수 있도록

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 양식의 :

편집 여기에 데이터를 삽입하는 코드입니다. 이상한 인코딩 문제가 원인 일 수 있습니까? 확실하지 않다. content 이후

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

유형의 텍스트 (응용 프로그램 엔진 타입) 나는 실제 결과를 얻기 위해 .getValue()를 사용하다 :

는 단순히 할 데이터를 검색합니다. 필자는 온라인 앱 엔진 데이터 저장소 뷰어에서 이상한 문자를 직접 볼 수 있기 때문에 데이터를 검색하는 데 문제가 있다고 생각하지 않습니다.

+0

\ n은 새 행의 표시 자입니다. 그게 당신이 말하는 겁니까? –

+1

인코딩 문제가 99 %입니다. 코드에서 인코딩을 어떻게 다루고 있습니까? 관련 스 니펫을 게시 할 수 있습니까? – systempuntoout

+0

@systempuntoout : 나는 그것을 다루지 않을 것이다. 내가해야 할 특별한 것이 있습니까? –

답변

0

이클립스를 사용하고 있습니까? 그렇다면 파일> 속성> 텍스트 파일 인코딩에서 파일이 UTF-8 인코딩인지 확인하십시오.

나는 추측하지 않을 것이다.

그래서 UTF-8로 변경하면 문제가 해결 될 것입니다. 내 모든 페이지가 UTF8로 인코딩되고 있었다 있도록

관련

디디에

+0

이것은 .java 소스 코드 인코딩만을 처리합니다. 이는 별도의 문제입니다. –

관련 문제