1. 查询编码
SHOW VARIABLES LIKE 'character_set_%'
2. 改数据库和单项
alter database tsdr character set utf8; set character_set_database=utf8;
set character_set_server=utf8;
此招好使!!!
3. vi /etc/my.cnf ,[mysqld]下的 port的下一行写入character-set-server=utf8 也可以设置成其他类型的字符编码,把utf8换成gbk等
重启服务器 service mysqld restart
jsp 设置
$.getJSON("/portal/edu/updateEdu?id="+id+"&item="+element.id+"&value="+encodeURI(element.value,"utf-8"),function(data){
});
后台java设置:
@RequestMapping("/updateEdu") public String updateEdu(Long id,String item,String value,HttpServletResponse response){ //String result = "{"result":"success"}"; try { URLDecoder.decode(value,"utf-8"); } catch (Exception e) { e.printStackTrace(); } eduService.updateById(id,item,value); JSONObject data = new JSONObject(); try { data.put("result", "success"); } catch (Exception e) { System.out.println(e.getMessage()); } PrintWriter out = null; response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); try { out=response.getWriter(); out.write(data.toString()); out.flush(); out.close(); return null; } catch (IOException e) { e.printStackTrace(); } return "redirect:/edu/getAllEdu"; }