应用服务器没有作到这一步,它只管bean(后台)与jsp(页面)之间信息的一致性,也就是说:bean是gbk那filter就配置gbk,而不是big5。
Oracle的JDBC连接机制没有能够指定字符集的,能不能考虑用存储过程来作?

解决方案 »

  1.   

    是以前存在数据库的数据读出都是乱码?还是连现在存入的数据也都是乱码?
    1、如果是以前存的数据是乱码,那你就只能把以前的数据重新存了,因为你以前存的时候是用SIMPLIFIED CHINESE_CHINA.ZHS16GBK存入的,而现在要用AMERICA_AMERICA.US7ASCII取出,不可能,这是数据库的问题,应该从数据库着手。
    2、如果是连现在存入的数据也都是乱码,那你在存入的时候就要进行字符集转换。
    public static String toChinese(String pstrWord) throws java.io.UnsupportedEncodingException
    {
    if ((pstrWord != null) && (!pstrWord.equals("")))
    {
    pstrWord = new String(pstrWord.getBytes("ISO8859_1"), "GBK");
    return pstrWord;
    }
    return "";
    }

    public static String ex_chinese(String str){
       if(str==null){
       str  ="" ;
       }
       else{
       try {
       str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
       }
       catch (Exception ex) {
       }
       }
       return str ;
    }public static String toReChinese(String pstrWord) throws java.io.UnsupportedEncodingException
    {
    if ((pstrWord != null) && (!pstrWord.equals("")))
    {
    pstrWord = new String(pstrWord.getBytes("GBK"), "ISO8859_1");
    return pstrWord;
    }
    return "";
    }
    用这几个方法试一下吧。
      

  2.   

    客户变态,我以前也见过这个问题的客户,主要是客户oracle原来用的那个字符集,后来说服客户了。
      

  3.   

    to:liaohaiying(小菜)
       你的方法是可以实现。问题正如我所说,jsp页面数量巨大,这才是叫人头疼的。to:zhugang(jumbo) 
       所有的字符处理都调用同一个方法去处理?我不大明白你的意思。一方面我使用动态生成SQL语句,返回的结果集都用同一方法处理,势必要提前转换查询结果。这个工作量还是恐怖。或者我的理解不对?
      

  4.   

    应该可以使用filter做统一转换,不知JDBC 3.0
      

  5.   

    public class SetCharacterEncodingFilter implements Filter {// ---------------------- Instance Variables  protected String encoding = null;  protected FilterConfig filterConfig = null;  protected boolean ignore = true;// ---------------------- Public Methods  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;
      }  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 destroy() {
        this.encoding = null;
        this.filterConfig = null;
      }// ------------ Protected Methods  protected String selectEncoding(ServletRequest request) {
        return (this.encoding);
      }
    }
      

  6.   


    TO  singedcat(以梦为马) :
    你写的过滤器是tomcat自己带的吧?一样没有用处的
      

  7.   

    呵呵,设计没有考虑层的问题!
    简单的办法就是临时增加一个数据处理层。找一个Encoding JDBC Driver,或者直接写一个,在写和读数据的时候增加Encode处理即可。
      

  8.   

    to:TinyJimmy(Jimmy)   以前我也好像看到一个jdbc driver,在连接的时候可以指定编码。只是现在找不到了。麻烦推荐一个如何?To  GJA106(中文字符)     不知道兄弟有什么成熟的想法没有,可否鉴戒 ?