用jqgrid异步获取列表值,遇到个问题,服务器端从数据库取到的数据没有出现中文乱码问题(日志打出来是没有乱码的),但是异步传到客户的时候却出现了乱码。 服务器端已经编码过了(UTF-8编码)。开始一直怀疑是客户端的问题,比如客户端和服务器端编码不一致啊,也怀疑是不是jqGrid工具函数中少配了 contentType: "application/x-www-form-urlencoded; charset=utf-8", 等等问题。
结果都不是,纠结了几个小时,后来经过大牛的提醒发现,原来代码还是出在服务器端,疏忽了。
@RequestMapping(value = "/searchUserList.form")
@ResponseBody
public void searchUserList(int page, int rows, HttpServletRequest request, HttpServletResponse response) throws IOException{
System.out.println("idcard="+idCard+"n page="+page+"n rows="+rows);
List list = userService.findByIDCard(idCard);
int totalRecord = list.size();
int totalPage = totalRecord%rows == 0 ? totalRecord/rows : (totalRecord/rows+1);
int index = (page-1)*rows;
int pageSize = rows;
String json = "{"total": ""+totalPage+"", "page": ""+page+"", "records": ""+totalRecord+"", "rows": [";
for (int i = index; i < pageSize + index && i 


