我在MYSQL中添加记录,例如:“我是辉”——在JSP运行时就出现“我是?”
在JSP中添加记录时,更是乱码,,,添加的都是乱码,,,
这该怎么解决??

解决方案 »

  1.   

    这是MySql的编码问题
       可以尝试下在链接MySql时指定编码格式为gbk或gb2312
      

  2.   

    就是gbk的啊,,,还乱码的啊...
      

  3.   

    就是在安装mysql的时候选择数据库的语言要用gb2312的。在就是可以在你的页面中尝试哈用字符转换的语句些哈的撒。
      

  4.   

    我给楼主的意见是最好把所有的编码格式该成UTF-8包括mysql安装时候也要选择UTF-8.
      

  5.   

    jsp和数据库的编码方式不同就会出现乱码,lz可以在更新数据库的时候进行转码。
      

  6.   

    你在数据库中取到数据后,假设保存为str,那么你可以用Java代码转换一下。Byte bytes = str.getByte("utf-8");
    String result = new String(bytes,"bg2312");这样子你试一下行不行,不行的话改一下上面两句话的编码方式试一下。
      

  7.   

    5楼正解,最好同意编码,全部搞成UTF-8
      

  8.   

    class Encoding extends RequestProcessor{
            public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // TODO Auto-generated method stub
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    super.process(request, response);
    }
    }
      

  9.   

    能说说在哪里改编码方式吗?
    有哪些地方???
    我知道在D:\Program Files\MySQL\MySQL Server 5.0里面有一个my.ini的文件
    [client]port=3306[mysql]default-character-set=gbk里的gbk可以改为UTF-8还有哪里也要改,,
    高手们指点指点啊...能说说UTF-8有哪些好处,,,而不用gbk呢,,,
      

  10.   


    这个是指在jsp,selvet和bean中都要保持一致...
      

  11.   


    I agree with this idea!
      

  12.   

    不是jsp的编码格式问题就是
    mysql的编码格式问题了。。
      

  13.   

    http://www.sqlserver.com.cn/c2l0ZS9zaG93Lmh0bWw_bXlpZD05NDY5url.html
    http://www.sqlserver.com.cn/c2l0ZS9zaG93Lmh0bWw_bXlpZD0xNjk2url.html
      

  14.   


    我在数据库中写入数据,我从数据库中取出来写入JSP中,在JSP显示是不乱码的啊...
    在JSP中写入数据库时就乱码啊...
    到底该怎么解释啊???
    能不能给我详细点的介绍介绍啊...
      

  15.   

    jsp  页面用 editplus 重新打开,选择“另存为” 它有个编码格式  选择 “utf-8”  就OK,另外你的页面中的<%page contentType="text/html;charset=gbk"%> 也要改成UTF-8
      

  16.   

    jsp  页面用 editplus 重新打开,选择“另存为” 它有个编码格式  选择 “utf-8”  就OK,另外你的页面中的<%page contentType="text/html;charset=gbk"%> 也要改成UTF-8MYSQL 中的编码最好是utf-8 tomcat 目录下的web.xml 中的编码格式也最好是utf-8
      

  17.   

    你看看数据库表中可是乱码,如果是的话,就说明是数据库编码不对喽。
    如果数据库中是正确的,就写个过滤器,把所有jsp文件都过滤一下,写个类继承Filter,然后在web.xml中配置一下就可以了
      

  18.   

    能说说在DREAMWEAVER8.0,TOMCAT6.0,MYSQL5.0三个配合的,有哪些地方涉及到编码方式了吗???...
    能指点一下吗???以后可以多注意了解一点...
      

  19.   

    安装mysql的时候选择数据库的语言为GBK
      

  20.   

    我的mysql已经安装在电脑上,但要改它的编码格式该在哪里改??
    总不会重新安装啊???
      

  21.   

    我的mysql已经安装在电脑上,但要改它的编码格式该在哪里改?? 
    总不会重新安装啊???
      

  22.   

    过滤器的在web.xml中的典型配置和主要代码如下: 
    web.xml:
    CharacterEncodingFilter
    net.vschool.web.CharacterEncodingFilter
    encodingGBKCharacterEncodingFilter
    /*
    CharacterEncodingFilter.java:public class CharacterEncodingFilter implements Filter 
    {protected String encoding = null; public void init(FilterConfig filterConfig) throws ServletException 
    {
    this.encoding = filterConfig.getInitParameter("encoding");
    }public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException 
    {
    request.setCharacterEncoding(encoding);
    response.setContentType("text/html;charset="+encoding);
    chain.doFilter(request, response);
    }} 
      不是你的机器的问题...不用重装数据库
      

  23.   

    在创建表或数据库时可以指定编码。
    create table test (....) DEFAULT CHARACTER SET utf8;楼主可以参考一下这篇文章:http://bbs.chinaunix.net/viewthread.php?tid=1177569
      

  24.   

    在数据库的链接的url上加上 ?characterEncoding=gbk 
    把数据库的编码格式、表的编码个格式和字段的编码格式都改为gbk。
      

  25.   

    如果是保存记录出现乱码的话,设置响应编码: response.setCharEncoding("GBK");如果是取得记录出现乱码的话,设置请求编码: request.setCharEncoding("GBK");
      

  26.   

    楼主,首先自己确认一下你那一环上面出问题了,再想办法解决.不要一个一个方法的试,这样效率太低了比如存到数据库中已是乱码,还是从数据库中读出来是乱码呢.WEB开发中乱码的可能性太多了。比如数据库中个别汉字是乱码其他汉字正常的情况都会存在的。
      

  27.   

    解决乱码:方案一)
    在相关的jsp中这样写:
    msg是你要过滤的乱码字符串
    <% 
       String message=request.getParameter("msg");
       String msg=new String(message.getBytes("IOS-8859-1"),"gbk");
    %>方案二)
    在相关的jsp中这样写:
    str是你要过滤的乱码字符串
    <%! public String transStr(String str)
        {
          try{
               return new String(str.getBytes("ISO-8859-1"),"gbk");
             }catch(){return str;}
        }
    %>   引用<%=transStr(message)%>
    方法三)
    在相关的jsp的头部这样写:
    <%@ page ContextType="text/html;charset="gbk"%>
    方法四)
    或者将可能要出现乱码的字符串存储到session,application中来避免乱码
    session.setAttribuite("str","str");方法五)
    使用filter过滤器:filter里边:
    public class ModifyCode implements Filter
      {
        protected FilterConfig filterConfig;
        private String targetEncoding="UTF-8";
        public void init(FilterConfig config)throws ServletException
          {
             this.filterConfig=config;
             this.targetEncoding=config.getInitParameter("code");//获取web.xml中code参数的值,即要过滤的字符串
          }    public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws ServletException
          {
             HttpServletRequest srequest=(HttpServletRequset)request;
             try
             {
               srequest.setCharacterEncoding(this.targetEncoding);//转码
                 chain.doFilter(request,response);
             }catch(Exception e)
                   {e.printlStackTrace();}
          }     public void destroy()
         {
            this.filterConfig=null;
         }
      }
    web.xml中的配置:
    <filter>
       <filter-name>modifyCode</filter-name>
       <filter-class>此filter的路径</filter-class>
       <init-param>
          <param-name>code</param-name>
          <param-value>UTF-8</param-value>
       </init-param>
    </filter><filter-mapping>
       <filter-name>modifyCode</filter-name>
       <url-pattern>/*</url-pattern> //过滤以所有的文件
    </filter-mapping>