Search code examples
jqueryjsongsonjquery-jtablecyrillic

jQuery jtable json, cyrillic encoding


I have a problem with sending data from server to page.

If I send:

{
 "Result":"OK",
 "Records":[
  {"PersonId":1, "Name":"Benjamin Button", "Age":17, "RecordDate":"\/Date(1320259705710)\/"},
  {"PersonId":2, "Name":"Douglas Adams", "Age":42, "RecordDate":"\/Date(1320259705710)\/"},
  {"PersonId":3, "Name":"Isaac Asimov", "Age":26, "RecordDate":"\/Date(1320259705710)\/"},
  {"PersonId":4, "Name":"Thomas More", "Age":65, "RecordDate":"\/Date(1320259705710)\/"}
 ]
}

Everything is OK, when I replace name to any cyrillic word it is viewed as

????????? ??? ?

At the top of every jsp page I put

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

From server side I send

    String a = new Gson().toJson(rowsList);
    StringBuilder sb = new StringBuilder();
    sb.append("{\"Result\" : \"OK\", \"Records\" : ");
    sb.append(a);
    sb.append("}");
    return sb.toString();

Solution

  • The problem was in Spring MVC.

    The solution reference is here

    Sending the responce as ResponseEntity object helped me

    @RequestMapping(value = "/reference-table/load")
    @ResponseBody
    public ResponseEntity<String> loadReferenceTable() {
    
        List rowsList = genericDao.selectAllRecords(ReferenceViewEntity.class.getName());
    
        StringBuilder sb = new StringBuilder();
        sb.append("{\"Result\" : \"OK\", \"Records\" : ");
        sb.append(new Gson().toJson(rowsList));
        sb.append("}");
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-type", "text/html;charset=UTF-8");
        return new ResponseEntity<String>(sb.toString(), headers, HttpStatus.OK);
    }