我采用的SQL server2000数据库 但是添加信息到数据库中显示中文乱码?求助给位了 多谢先!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【juchao】截止到2008-06-23 22:41:13的历史汇总数据(不包括此帖):
    发帖数:30                 发帖分:1822               
    结贴数:22                 结贴分:1242               
    未结数:8                  未结分:580                
    结贴率:73.33 %            结分率:68.17 %            
    楼主加油
      

  2.   

    1.页面,数据库和Filter中的编码必须一致
    2.可以设置tomcat的uri encoding
      

  3.   

    这里有怎么改 tomcat的encodinghttp://topic.csdn.net/u/20080612/20/d31529ab-c98e-4893-931b-68cc0e9f5b87.html
      

  4.   

    在处理提交页面的文件中加入这样一条语句:request.setCharacterEncoding("GBK");就可以了
      

  5.   

    我觉得是和数据库本身的编码方式有关,和页面无关,如果是简体中文,头部加上<%@ page contentType="text/html; charset=GB2312" %>就应该没问题,这并不需要编码转换,jsp编译器会自动转换编码方式,除非你提交的是繁体中文..
    个人认为是数据库字符编码设置问题
      

  6.   


    头部加上 <%@ page contentType="text/html; charset=GB2312" %> 提交页面的文件中加入 request.setCharacterEncoding("GBK");
      

  7.   

    分别显示设置tomcat,url,jsp,数据库的编码为GB2312
      

  8.   

    我的博客上有解决乱码的方法可以去看看:http://blog.csdn.net/java2xw/archive/2008/05/06/2404079.aspx
      

  9.   

    楼主先看一下,往数据库中存储的数据是不是在页面中已经是乱码了?
    因为sqlserver2000数据库已经解决了中文乱码问题.
    所以你的乱码应该是在存之前已经是乱码了.
    可以将页面
    <%@ page contentType="text/html; charset=GB2312" pageEncoding="gbk2312"%>
    在针对性地处理页面乱码就OK了. 
      

  10.   

    是不是安装的SQL2K英文版?
    你按以下方式对得到的值进行编码试一下
     String userName = request.getParameter("username");   
    userName = new String(userName.getBytes("8859_1"),"gb2312");
      

  11.   

    http://blog.csdn.net/rascalboy520/archive/2008/06/06/2516038.aspx
    这里有一些相关的问题,你看一下吧,
      

  12.   

    ***代表支持中文的字符集
    JSP中:
    <%@ page contentType="text/html; charset=***" %>servlet或filter中:
    request.setCharacterEncoding("***");
    response.setContentType("text/html; charset=***");
    SQL server2000中:
    也用相同的字符集***
      

  13.   

    建议存数据的时候用UTF-8进行转换再存储, 数据库可以设置成GBK, 页面统一编码UTF-8
      

  14.   

    我在用jsp编写程序时也遇到过你说的类似情况;这个是编码问题只要你把这个值转化下就可以了
    变量=(new String(添加的信息.getBytes("iso-8859-1"),"gb2312")
    或变量=(new String(添加的信息.getBytes("iso-8859-1"),"gb2312")
      

  15.   

    有两点,看你的提交方式是post还是get来确定,最好两个都加
    第一加一个过滤器
    public class ChineseFilter implements Filter {  private FilterConfig filterConfig;     public void init(FilterConfig filterConfig) throws ServletException {
             this.filterConfig = filterConfig;
         }     public void doFilter(ServletRequest request, ServletResponse response,
                 FilterChain filterChain) {
             try {
              
                 //String encoding=filterConfig.getInitParameter("enconing");//也可动态从WEB.xml配置文件中取出参数,这样我们可以通过配置修改编码格式.
                 request.setCharacterEncoding("gbk");//设置请求的编码格式
                 response.setCharacterEncoding("gbk");
                 filterChain.doFilter(request, response);
             } catch (ServletException sx) {
                 filterConfig.getServletContext().log(sx.getMessage());
             } catch (IOException iox) {
                 filterConfig.getServletContext().log(iox.getMessage());
             }
         }
           public void destroy() {
         }第二,如果你是用的tomcat就在server.xml文件<Connector>这个节点中加上URIEncoding="gbk"
      
      

  16.   

    lz的设置只是限制在本页面使用gb2312,但是request过来的东西并不是gb2312的,建议用个过滤器
      

  17.   

    试试用UTF-8或者在接收的时候转码
      

  18.   

    过滤器完整的实现1、修改Tomcat的配置文件Server.xml,打开该方法,找到8080端口的Connector标签,注意看看自己的Tomcat端口是不是8080,如果不是注意找到对应端口的Connector,在该标签中增加URIEncoding=“GBK”,保存Server.xml并关闭 2、增加过滤器Filter,可以从Tomcat自带的例子中复制,其代码如下:  package filters;
    import java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.UnavailableException;
    public class SetCharacterEncodingFilter implements Filter {
    protected String encoding = null;
    protected FilterConfig filterConfig = null;
    protected boolean ignore = true;public void destroy() {this.encoding = null;
    this.filterConfig = null;}
    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain)
    throws IOException, ServletException {// Conditionally select and set the character encoding to be used
    if (ignore || (request.getCharacterEncoding() == null)) {
    String encoding = selectEncoding(request);
    if (encoding != null)
    request.setCharacterEncoding(encoding);
    }// Pass control on to the next filter
    chain.doFilter(request, response);}
    public void init(FilterConfig filterConfig) throws ServletException {this.filterConfig = filterConfig;
    this.encoding = filterConfig.getInitParameter("encoding");
    String value = filterConfig.getInitParameter("ignore");
    if (value == null)
    this.ignore = true;
    else if (value.equalsIgnoreCase("true"))
    this.ignore = true;
    else if (value.equalsIgnoreCase("yes"))
    this.ignore = true;
    else
    this.ignore = false;}
    protected String selectEncoding(ServletRequest request) {return (this.encoding);}
    }
    3、在web.xml中增加下面代码:<filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>filters.SetCharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>GBK</param-value>
    </init-param>
    </filter> <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>4、编写JSP文件,在文件头部增加代码:<%@ page pageEncoding="GBK"%>或者<%@ page contentType="text/html;charset=GBK"%>根据以上步骤,重新启动Tomcat服务,即可正确显示中文
      

  19.   

    过滤器完整的实现1、修改Tomcat的配置文件Server.xml,打开该方法,找到8080端口的Connector标签,注意看看自己的Tomcat端口是不是8080,如果不是注意找到对应端口的Connector,在该标签中增加URIEncoding=“GBK”,保存Server.xml并关闭 2、增加过滤器Filter,可以从Tomcat自带的例子中复制,其代码如下:  package filters;
    import java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.UnavailableException;
    public class SetCharacterEncodingFilter implements Filter {
    protected String encoding = null;
    protected FilterConfig filterConfig = null;
    protected boolean ignore = true;public void destroy() {this.encoding = null;
    this.filterConfig = null;}
    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain)
    throws IOException, ServletException {// Conditionally select and set the character encoding to be used
    if (ignore || (request.getCharacterEncoding() == null)) {
    String encoding = selectEncoding(request);
    if (encoding != null)
    request.setCharacterEncoding(encoding);
    }// Pass control on to the next filter
    chain.doFilter(request, response);}
    public void init(FilterConfig filterConfig) throws ServletException {this.filterConfig = filterConfig;
    this.encoding = filterConfig.getInitParameter("encoding");
    String value = filterConfig.getInitParameter("ignore");
    if (value == null)
    this.ignore = true;
    else if (value.equalsIgnoreCase("true"))
    this.ignore = true;
    else if (value.equalsIgnoreCase("yes"))
    this.ignore = true;
    else
    this.ignore = false;}
    protected String selectEncoding(ServletRequest request) {return (this.encoding);}
    }
    3、在web.xml中增加下面代码:<filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>filters.SetCharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>GBK</param-value>
    </init-param>
    </filter> <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>4、编写JSP文件,在文件头部增加代码:<%@ page pageEncoding="GBK"%>或者<%@ page contentType="text/html;charset=GBK"%>根据以上步骤,重新启动Tomcat服务,即可正确显示中文
      

  20.   

    转换一下编码试试。 。     用GBK。。
      

  21.   

    我觉得应该和数据库的字符集有关系...
    你存放中文信息的栏位的需要以Unicode的方式存放
    ...INSERT INTO table values(N'中文' ......)