1,前台传递到后台乱码,在ajax请求时添加
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
scriptCharset:"UTF-8",
2,后台发送到前台乱码
response.setContentType("text/html;charset=utf-8"); //当然如果是json数据,需要设置为("text/javascript;charset=UTF-8");
response.getOutputStream().write(jsonData.toString().getBytes("UTF-8"));
3,添加过滤器
servletRequest.setCharacterEncoding("UTF-8");
servletResponse.setCharacterEncoding("UTF-8");
filterChain.doFilter(servletRequest,servletResponse);