我有一个问题,是关于中文乱码问题。
我用的是Eclipse3.1+tomcat5.5+struts,数据库是SQLServer。
在添加时JSP页面用的是<%@ page contentType="text/html;charset=gb2312"%>标签;
用FormBean接收,输出到后台时是乱码,但写到数据库中则是中文;
但为什么从数据库提取纪录输出到页面时还是乱码呢?
我很着急,希望各位前辈多多指点我,我会给分的!!!!!!

解决方案 »

  1.   

    <%@ page contentType="text/html;charset=UTF-8"%>
      

  2.   

    String s = new String("你的记录".getBytes("iso-8859-1"), "gbk") ;out.print(s) ;
      

  3.   

    页面表单里的东西按照你的charset设置变成字节流,传到后台程序。后台必须设置相对应的编码才能正确解码。如果没有设置会使用默认的西文编码来解码,这样中文肯定变成乱码。至于数据库可以正常显示可能是恰巧设置了相同的编码。
    用这个设置一下看看好用不
    request.setCharacterEncoding("gb2312");
      

  4.   

    看看这里: 
    http://www.blogjava.net/rickhunter/articles/33571.html
      

  5.   

    String s = new String("FormBean的属性".getBytes("iso-8859-1"), "gbk") ;
      

  6.   

    乱码的终结解决办法:
    http://www.newxy.net/doc.jsp#anchor5.5
      

  7.   

    DB字符集用UTF-8,
    网页encoding也用UTF-8,什么事都不会有,随便几种语言
      

  8.   

    request.setCharacterEncoding("gb2312");
      

  9.   

    Sql server2000 似乎没有设置字符集的地方。应该是跟数据库的语言设置有关。不过再插入字符型数据前加一个N就是unicode。
    像这样 N'你好',存进去的是unicode。
    sql server2005没有用过不知道。
      

  10.   

    String str = new String("记录".getBytes("ISO-8859-1"),"gb2312");
      

  11.   

    这是我总结的一些解决方案,不知对LZ有帮助没
    1: 安装MySQL数据库时候就指定字符集合为gbk或者gb2312,只要数据库中显示正常中文字符的话,页面肯定显示正常,哪来这么多的转换,烦死了!!
    2: 指定服务器的 编码   GBK   或者GB23123: 修改安装目录下的  初始化配置文件   my.ini# The TCP/IP Port the MySQL Server will listen on
    port=3306
    #Path to installation directory. All paths are usually resolved relative to this.
    basedir="E:/MySQL5/"#Path to the database root
    datadir="E:/MySQL5/Data/"# The default character set that will be used when a new schema or table is
    # created and no character set is defined
    default-character-set=latin1             换成  gbk   或者  gb2312# The default storage engine that will be used when create new tables when
    default-storage-engine=INNODB