JSP的request 默认为ISO8859_1,所以在处理中文的时候,
要显示中文的话,必须转成GBK的,如下
String str=new String(request.getParameter("name").getBytes("ISO8859-1"),"GBK");
out.println(str);
这样就可以显示中文了
MYSQL操作时的中文问题:
这个要看MySQL的默认编码了,一般不调整的话为latin1其实和ISO8859_1一样,所以操作的时候要处理
和他一致,不然就会乱码的
1.插入中文:
String sql2="INSERT INTO test (name) VALUES('"+request.getParameter("name")+"')";
stmt.executeUpdate(sql2);
不用编码就可以插入了
2.显示插入的中文:
因为存入的是latin,所以显示的时候就要GBK一下
String x=new String((rs.getString("title")).getBytes("ISO8859_1"),"GBK");
out.println(x);
3.设定存储编码:
当然在MySQL为latin1编码时,也可以存的时候用GBK了
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jsp?
useUnicode=true&characterEncoding=GBK","root","");
str1="中文";
String sql2="INSERT INTO test (name) VALUES('"+str1+"')";
这样也可以很成功的插入
http://user.qzone.qq.com/372806800/blog/1336199262
|
相关文章
- [itint5]跳马问题加强版
- MySQL之改_update
- MySQL索引的使用方式和缺点
- 通病问题:错误如for architecture arm64: "_OBJC_CLASS_$_CBUUID", referenced from: objc-class-ref in BluetoothLinkOperation.o 类似的问题解决办法
- Python字符串编码问题
- 【kate总结】Matlab坐标轴问题
- MySQL导出数据文件
- MySQL if,ifnull,nullif 函数
- MySQL中的IFNULL,IF,NULLIF函数
- 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)