- response.setContentType("application/json;charset=utf-8");//指定返回的格式为JSON格式
- response.setCharacterEncoding("UTF-8");//setContentType与setCharacterEncoding的顺序不能调换,否则还是无法解决中文乱码的问题
//4.根据接收的数据,查询数据库 boolean flag=loginUserDao.changePass(name,pwd); System.out.print("====flag===="+flag+"\n"); String str; if (flag==true){ str ="{\"id\":\"1\",\"msg\":\"更改成功\"}"; }else { str ="{\"id\":\"0\",\"msg\":\"更改失败\"}"; } PrintWriter out=null; try { out= response.getWriter(); out.write(str); } catch (IOException e) { e.printStackTrace(); }