2

I have two comboboxes "A" & "B". Combo "B" is populated using jQuery Ajax (dataType:json) when a value in Combo "A" is selected (onchange event).

There are cases where part of the data in "B" can be chinese/international, in which case the data appears as "????" in the browser.

Typically the entire setup is like so:

ERP <---> Servlet <---> JSP <---> Browser

ERP is UTF-8 enabled. I can clearly see the data in chinese in the ERP console. I've dumped the resultant data that passes into the servlet in a file just to check if it's proper. It's perfectly encoded. I've set the contentType for JSPs to UTF-8. Everything's in place.

I've added the necessary contentType in Ajax to "application/json;charset=utf-8". Still no dice.

That leaves the browser. I've used every browser there is and the same issue arises. I've noticed that the browser simply isn't able to understand the charset of the chinese data when populated on-the-fly.

What can possibly be going wrong? Due to security reasons I cannot post the code. I'd be grateful for any sort of advice.

Thanks a heap! ~Sabier

user429573
  • 21
  • 1

1 Answers1

0

If you have set your JSP as UTF-8 and your resulting contentType is set to UTF-8 also, you could try this

1) What about using contentType params when you call the servlet, as shown in https://stackoverflow.com/a/6283111/1078487

$.ajax({
      type: "POST",
      url: "yourservlet",
      dataType: "text",
      data: {yourparams},// here we def wich variabe is assiciated
      contentType: "application/x-www-form-urlencoded; charset=UTF-8",
      success: function(data) {
         //population
      }
});

2) Even if your ERP is setted as UTF-8, just double check those returning string using a UTF-8 byte conversion and see what happens.

byte[] utf8Bytes = stringToParse.getBytes("UTF8");
String stringToReturn = new String(utf8Bytes, "UTF8");
Community
  • 1
  • 1
Carlos Quijano
  • 1,566
  • 15
  • 23