欢迎光临
我们一直在努力

Java 中文问题的解决-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

java 中文问题一直困扰许多学习者。总结了下面的一些情况的解决方法。

希望对大家有帮助。

连接 mysql database server:

——————————————————————————-

mysql 不支持 unicode,所以比较麻烦。

将 connectionstring 设置成 encoding 为 gb2312

string connectionstring

= "jdbc:mysql://localhost/test?useunicode=true&characterencoding=gb2312";

测试代码:

string str = "汉字";

preparedstatement pstmt = conn.preparestatement("insert into test values (?)";

pstmt.setstring(1,str);

pstmt.executeupdate();

数据库表格:

create table test (

name char(10)

连接 oracle database server

——————————————————————————-

在把汉字字符串插入数据库前做如下转换操作:

string(str.getbytes("iso8859_1","gb2312"

测试代码:

string str = "汉字";

preparedstatement pstmt = conn.preparestatement("insert into test values (?)";

pstmt.setstring(1,new string(str.getbytes("iso8859_1","gb2312";

pstmt.executeupdate();

servlet

——————————————————————————-

在 servlet 开头加上两句话:

response.setcontenttype("text/html;charset=utf-8";

request.setcharacterencoding("utf-8";

jsp

——————————————————————————-

在 jsp 开头加上:

<%@ page contenttype="text/html; charset=gb2312" %>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Java 中文问题的解决-JSP教程,Java技巧及代码
分享到: 更多 (0)

相关推荐

  • 暂无文章