1

using this code i persist data to GAE Store but when storing Arabic it's format in Store become ?????

how to support persist Arabic Text in GAE ?

the code :

    PersistenceManager manager = PMF.get().getPersistenceManager();
    Category category = new Category(categoryName);
    manager.makePersistent(category);
    manager.refresh(category);
    manager.close();
Ahmed Aswani
  • 8,271
  • 7
  • 33
  • 54
ahmed Shoeib
  • 254
  • 6
  • 22

1 Answers1

1

It's more likely that the text is corrupted when you submit it from a form, or render it to HTML, rather than when it is stored (or retrieved).

As a quick test, try this:

String test = "\u0627\u0644\u0633\u0644\u0627\u0645";
PersistenceManager manager = PMF.get().getPersistenceManager();
Category category = new Category(test);
manager.makePersistent(category);
manager.refresh(category);
manager.close();

If that displays correctly (السلام), then the problem is with the way the input is handled on its way into the application. If it still appears corrupted, try another test where you retrieve the category name, and within your application, compare it to the original value of test. The test might look something like this:

boolean okay = "\u0627\u0644\u0633\u0644\u0627\u0645".equals(category.getName());

Log (or display) the value of okay. If false, then it really is the persistence layer that can't handle Arabic. Post your findings, and we'll work toward a solution once we are more confident where the problem truly is.


Update: The servlet engine is not guaranteed to recognized the character encoding if you set it via setHeader(). Use the setContentType() method or the setCharacterEncoding() method instead.

erickson
  • 265,237
  • 58
  • 395
  • 493
  • @ahmed Shoeib - What about the second test? Did you retrieve the category and compare its name to the original string? – erickson May 21 '11 at 18:28
  • in the server side i print the value of categoryName and i found that it is arabic but when adding it to store it's format convert to ??? – ahmed Shoeib May 21 '11 at 21:33
  • i deployed the project on GAE and i persist this word "سياسه " it is mean "political" in English ... this word persisted right in the Storr as "سياسه " ... but when displaying its appear as ????? so what is the problem in that ??? – ahmed Shoeib May 22 '11 at 09:18
  • @ahmed - What is the encoding of the web page on which it is displayed? You will have to use an encoding that supports Arabic, like ISO-8859-6 or UTF-8. And, how did you verify that "this word persisted right in the [store] as 'سياسه'"? – erickson May 22 '11 at 19:04
  • the encoding of the response resp.setHeader("Content-type","text/html; charset=utf-8"); and how i verify that the word persisted right . after deploying the code checked the store viewer and i found that the data persisted in the right format – ahmed Shoeib May 22 '11 at 19:34
  • 1
    @ahmed - I am not sure if the generic `setHeader()` method will set the character encoding as is specified explicitly for the `setContentType()` method. (The specification doesn't say what `setHeader()` should do in this case, and it's a custom Google servlet engine.) So, **before** calling `getWriter()`, call `setContentType("text/html; charset=UTF-8")`. Get rid of the `setHeader('content-type", ...)` call you are currently making. Before you do any of this, you might want to verify the page encoding in the browser. – erickson May 23 '11 at 03:52