如用Servlet的话,我倒是有一招,你自已在JSP页面上试试吧在doGet()或doPost()中写
1. request.setCharacterEncoding("GB2312") 这是Servlet从JSP读到数据后,再向数据库添加信息的中文支持
2. response.setContentType("text/html; charset=GB2312") 这是Servlet向JSP写数据时用的中文支持这样就可支持中文了

解决方案 »

  1.   

    public class Function
    {
    public static String trans(String chi)
        {
    String result = null;
            byte temp [];
            try
             {
                  temp=chi.getBytes("iso-8859-1");
                  result = new String(temp);
              }
              catch(UnsupportedEncodingException e)
              {
                     System.out.println (e.toString());
              }
    return result;
    }
    } 在每次将数据写到数据库之前trans(result)一下,result是你要写的数据
      

  2.   

    假设name是你将要插进数据库的变量:    
    String nameInstadOf = new String(name.getBytes("iso-8859-1"),"GBK");
    此时所得到的nameInstadOf插入数据库后将可解决乱码的问题!
      

  3.   

    加一句
    request.setCharacterEncoding("GBK") 
    就可以了
      

  4.   

    就我上面的代码要怎样加呢?PreparedStatement stm=con.prepareStatement("insert into message values(?,?,?,?,?)");
    stm.setString(1,msg.getTitle());
    stm.setString(2,msg.getName());
    stm.setDate(3,new java.sql.Date(new java.util.Date().getTime()));
    if((msg.getEmail()).length()==0)
    stm.setString(5,null);
    else stm.setString(5,msg.getEmail());
    stm.setString(4,msg.getContent());
      

  5.   

    再上面的bean获得属性后就进行转换,不过不同的数据库有不同的编码
      

  6.   

    举个例子:
    String title=result.getString("title");
    改成
    String title=trans(result.getString("title"));
      

  7.   

    把Function那个类import进来,在使用它的函数
      

  8.   

    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 {
            if (ignore || (request.getCharacterEncoding() == null)) {
                String encoding = selectEncoding(request);
                if (encoding != null)
                    request.setCharacterEncoding(encoding);
            }
            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);    }
    将这个SetCharacterEncoding.java文件编译一下!并在web.xml文件中配置:
    <filter> <filter-name>SetCharacterEncoding</filter-name>
    <filter-class>Filters.SetCharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name>
    <param-value>GB2312</param-value> </init-param> </filter> <filter-mapping> <filter-name>SetCharacterEncoding</filter-name>
    <url-pattern>/*</url-pattern>    </filter-mapping>
      

  9.   

    把request.setCharacterEncoding("GBK") 加到你所有的request.********************前边,不可以吗?我也是刚学了不久