0

I have an application that performs an Ajax call where a string is passed to the server and the server returns a json string containing the same String, among other information. I have this application hosted on a server in Amazon Web Services (AWS) and in my local development environment.

When I pass through this call special characters (á, ñ, etc.) in the AWS environment, they return in the json as a diamond with a question mark. The mystery is that the characters are properly encoded in my local development environment.

I have this tag to encode the HTMLtemplates:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Also i got the server annotation:

@RequestMapping(value="/actualizarDestinos", produces = "application/json; charset=utf-8", method = RequestMethod.GET)

Within the tomcat configuration in web.xml, I uncommented this filter setCharacterEncodingFilter.

Any idea why the encoding fails in the AWS environment but works in my local environment? Does it have something to do with the language of the operating system?

WLux
  • 90
  • 12
  • Tried adding the filter encodingFilter on web.xml and -Dfile.encoding=UTF8 on Tomcat Java Options. Still no luck. Wonder if I will have something to do with the OS language or if its bug in Windows Server 2012 r2. – WLux Jan 20 '15 at 21:55

2 Answers2

1

In my case, tomcat, specify URIEncoding=utf8 property in tag in server.xml file

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="utf8" />

and set the LANG system environment as UTF8 (like en_US.UTF-8) and restart WAS and try it again.

minchang
  • 9
  • 2
  • I tried both URIEncoding="utf8" and "UTF-8" with no luck. The instance got Windows Server 2012 R2, any way to change it there? – WLux Jan 20 '15 at 02:58
  • 1
    @MiguelAngelMerinoVega try add encodingFilter into web.xml in your web-app project. not tomcat configuration diretory. ` encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 encodingFilter your serviet name ` – minchang Jan 20 '15 at 04:33
  • Tried it and uploaded a new version. Still no luck. – WLux Jan 20 '15 at 05:22
  • Could it be language? Here my SO is in Spanish and the application works fine. In the other place -where it fails- is in English. – WLux Jan 20 '15 at 05:25
  • @MiguelAngelMerinoVega then, may be language setting is the problem XD. I don't have experience on windows server . sorry. ;; – minchang Jan 20 '15 at 08:53
0

After months I could solve the problem thanks to this answer

https://stackoverflow.com/a/138950/1566419

Community
  • 1
  • 1
WLux
  • 90
  • 12