Today encountered such a problem, call the java with js get request, json data obtained Chinese does not display properly, jsp files are stated utf-8 format, a lot of inquiries, found problems in the @ResponseBody
@ResponseBody default encoding format ISO-8859-1
, needs to be modified, added content produces in the @GetMapping
Reference: SpringMVC @ResponseBody distortion, UTF-8 format compatible
java code
@Controller
public class ExamController {
@Autowired
private ExamService examService;
@GetMapping(value = "/getPaper", produces = "application/json; charset=utf-8")
@ResponseBody
public String getPaper(HttpSession session) {
Paper paper = null;
try {
paper = this.examService.getPaper();
}catch(SystemException e){
session.setAttribute("msg", e.getMessage());
}catch(Exception e1) {
e1.printStackTrace();
}
System.out.println(paper.toString());
return paper.toString();
}
}