controller响应给前端的数据中包含中文,前端解析所得显示结果出现乱码。
@RequestMapping("ajaxReq")
public void ajaxReq(HttpServletRequest req,HttpServletResponse resp) throws IOException{
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String username = req.getParameter("username");
String password = req.getParameter("password");
resp.getWriter().write(username+" : "+password);
}
@RequestMapping(value="ajaxReq",produces="text/html;charset=utf-8") @ResponseBody public String ajaxReq(HttpServletRequest req,HttpServletResponse resp) throws IOException{ String username = req.getParameter("username"); String password = req.getParameter("password"); return username+" : "+password; }
原文:https://www.cnblogs.com/wxinyi/p/13275193.html