通过Get方式提交参数,url:
http://localhost:8080/Minisite/light?nick="aaa"&mobile=""&prov="江西"&city="景德镇"&game="对对碰"Servlet里面的doGet代码:
String nick = new String(req.getParameter("nick").getBytes("ISO-8859-1"),"UTF-8");
String mobile = new String(req.getParameter("mobile").getBytes("ISO-8859-1"),"UTF-8");
String prov = new String(req.getParameter("prov").getBytes("ISO-8859-1"),"UTF-8");
String city = new String(req.getParameter("city").getBytes("ISO-8859-1"),"UTF-8");
String game = new String(req.getParameter("game").getBytes("ISO-8859-1"),"UTF-8");
LightMap lm = new LightMap();
lm.insertLightRecord(nick, prov, city, game, mobile);
数据库采用的是utf8编码。
如果将Servlet的doGet代码改成
String mobile = new String(req.getParameter("mobile").getBytes("ISO-8859-1"),"GBK");那么这个字段中文就不会乱码
请问哪位能帮帮我。在线等。谢谢!(新手,如果可以的话能不能讲的稍微详细一点)

解决方案 »

  1.   

    第一:调试查看从url得到的中文数据是否是乱码。注意tomcat的request提取方法,并不是所有servlet容器都这样子处理!
    第二:查看数据库jdbc的url字符串是否指定了正确的编码
      

  2.   

    http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
    MySQL 中文显示乱码
      

  3.   

    你用的是tomcat吗?在conf目录下的server.xml文件中的connector节点加上URIEncoding="gbk"
      

  4.   

    是的。我数据库用的编码是utf-8,这个URIEncoding属性还是设置成"gbk"吗?还是要改成"utf-8"。
      

  5.   

    String mobile = new String(req.getParameter("mobile").getBytes("ISO-8859-1"),"GBK");你这里不是转换成GBK就不乱码了么