2

I'm developing a web application in Spring Framework under Wildfly 10 application server. I use Eclipse IDE.

I experienced problems with the character encoding which I wasn't able to solve: some of the characters doesn't appear properly when I send them from server side to client side.

My test String object I use is "árvíztűrő tükörfúrógép"

  1. When I read the value from database and send it to the client side, everything appears fine.
  2. When I set the String value in the Controller as a ModelAndView object, it appears as '??rv?­zt?±r?? t??k?¶rf??r??g?©p'
  3. When I send the value from client side by ajax as a POST variable and send it back to client side, it appears as 'árvízt?r? tükörfúrógép'.

I set all the .jsp files encoding UTF8: <%@page contentType="text/html" pageEncoding="UTF-8"%>

In Eclipse I set all the Maven modules text file encoding to UTF8. All the files are in UTF8.

What did I miss? What else should I set to get the String value right on client side? Should I set the character encoding in Wildfly 10 somehow?

Could somebody help me? If you need further information, please don't hesitate to ask. Thank you.

EDIT: Setting the character encoding as Maven property solved the second case. Now I only have problems with the third case:

<properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Igorovics
  • 416
  • 1
  • 7
  • 25
  • 1
    Did you try to step through your code with a debugger to see where the strings start to get corrupted? – Thomas Oct 07 '16 at 13:55
  • Thomas: Yes. On the server side everything looks fine, no matter whether the value came from client side, or from the database (obviously tha manually set String looks fine, too). On the client side I can see what is in the post. – Igorovics Oct 07 '16 at 14:03
  • Bonus information: When I write the value to a JSONObject, the accented characters already look bad even on the server side. – Igorovics Oct 07 '16 at 14:03
  • I mean, if I get the value from the client side and put it into the JSONObject, they look fine in the JSONObject. If I put the value manually, they look rubbish. – Igorovics Oct 07 '16 at 21:43

1 Answers1

3

After nearly 2 months of searching I was able to find solution to my problem. In addition to configure the server and Spring, I needed to add two more things:

On the web module of my Maven project I had to set the character encoding of the source: <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Also when I sent JSONObject to client side, I had to set the character encoding: @RequestMapping(value = "/historyContent.do", produces = { "application/json; charset=UTF-8" })

And finally I can see what I wanted.

Igorovics
  • 416
  • 1
  • 7
  • 25