您的位置:程序门 -> java -> web 开发



我不相信你是高高手,不然你就进来看看


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


我不相信你是高高手,不然你就进来看看[无满意答案结贴,结贴人:xpice]
发表于:2007-09-13 16:05:01 楼主
mulitpartrequest   mr=new   multipartrequest(request,savedir,maxsize, "gbk ");

string   type=mr=getparameter( "type ");
out.println(type);
//在jsp里是正常的,因为jsp里有
// <%@page   contenttype= "text/html;charset=gb2312 "%>
//在servlet   里加上gb2312也可以,但就是写入数据库就是???


???何解???????????????/
数据库是mysql

在插入数据库前就得新编码了!
string   type=new   string(mr.getparameter( "type ").getbytes( "utf-8 "), "gb2312 ");

string   type=new   string(mr.getparameter( "type ").getbytes( "gb2312 "), "gb2312 ");

string   type=new   string(mr.getparameter( "type ").getbytes( "iso-8859-1 "), "gb2312 ");

过滤器//request.setcharacterencoding( "gb2312 ");
    //中文转换
        public   static   string   tochinese(string   str)   {
        if   (str   ==   null)   {
            return   null;
        }
        try   {
            return   new   string(str.getbytes( "iso-8859-1 "),   "gb2312 ");
        }
        catch   (unsupportedencodingexception   ex)   {
            return   " ";
        }

  以上这些,知道的不知道的(我把数据库的编码也改成gb2312/iso-8859-1/utf-8)都用了,我崩溃到死的边缘了
发表于:2007-09-13 16:16:011楼 得分:0
我以前遇到过,但忘记怎么解决的了,我那时也用的mysql,你仔细检查一下,你用的是tomcat还是weblogic或别的什么,可能是这方面的原因
发表于:2007-09-13 16:19:292楼 得分:0
用的就是tomcat5.0
发表于:2007-09-13 16:26:373楼 得分:0
这个要设置mysql数据库支持中文
具体我有点忘记了,你自己试试
发表于:2007-09-13 16:31:374楼 得分:0
把mysql语言设置为gb2312
发表于:2007-09-13 16:48:335楼 得分:0
shalei1983()  
早试过了
发表于:2007-09-13 17:09:516楼 得分:0
mysql写连接的时候可以设置编码,你试下吧。
发表于:2007-09-13 17:18:567楼 得分:0
路过
发表于:2007-09-13 17:40:358楼 得分:0
以小弟看来可以试试这个
1.你在servlet里request时这么做request.setcharactorencoding( "gb2312 ");
2.确保数据库表是gb2312
3.也可以做个servlet的过滤器
发表于:2007-09-13 22:03:329楼 得分:0
out.println(type);
system.out.println(type);

怎么不在插入数据库之前   打印到控制台试试?
发表于:2007-09-14 01:09:3810楼 得分:0
帅哥,你好像用反了吧??嘎嘎
运行一下这个程序。
public   class   getectext   {
public   static   void   main(string[]   args)   {
      string   encoding   =   system.getproperty( "file.encoding ");
      system.out.println( "default   system   encoding: "   +   encoding);
}
}
看看返回的字符集是什么?

插入数据需要将这个系统字符集合转化为数据库字符集合

查询数据需要数据库字符集合转化为系统字符集合

查看数据库字符集合这个你自己办吧!帅哥!


快速检索

最新资讯
热门点击