你装Linux时选的什么语言环境?还有你的tomcat是什么语言的?mysql呢?

解决方案 »

  1.   

    在bean裏加入下面這段代码试试,再導入jsp文件中去
     /**
       * 解决中文问题,ISO转为GBK编码,用于POST,GET方式取得数据
       * @param str 原始文本
       * @return 转码后的文本
       */
      public String iso2gb(String str) {
          if (str != null) {
              byte[] tmpbyte=null;
              try {
                  tmpbyte=str.getBytes("ISO8859_1");
              }
              catch (UnsupportedEncodingException e) {
                  System.out.println("Error: Method: dbconn.iso2gb :"+e.getMessage());
              }
              try {
                  str=new String(tmpbyte,"GBK");
              }
              catch(UnsupportedEncodingException e) {
                  System.out.println("Error: Method: dbconn.gb2iso :"+e.getMessage());
              }
          }
          return str;
      }  /**
       * 解决中文问题,GBK转ISO编码,用于从数据库中存入转码
       * @param str 原始文本
       * @return 转换后文本
       */
      public String gb2iso(String str) {
          if (str != null) {
              byte[] tmpbyte=null;
              try {
                  tmpbyte=str.getBytes("GBK");
              }
              catch(UnsupportedEncodingException e) {
                  System.out.println("Error: Method: dbconn.gb2iso :"+e.getMessage());
              }
              try {
                  str=new String(tmpbyte,"ISO8859_1");
              }
              catch(UnsupportedEncodingException e) {
                  System.out.println("Error: Method: dbconn.gb2iso :"+e.getMessage());
              }
          }
          return str;
      }}
      

  2.   

    给你一个字符转换的类,你在活的参数向数据库插入的时候调用,从数据库里取出来的时候不用转换就可。数据库是Oraclepublic class ConvertCharSet
    {
    public static String GBKToISO88591(String str)
    {
    if(str == null) return str;
    try
    {
    return new String(str.getBytes("GBK"),"8859_1");
    }
    catch(Exception  usex)
    {
    return str;
    }
    } public static String GBKToGB2312(String str)
    {
    if(str == null) return str;
    try
    {
    return new String(str.getBytes("GBK"),"GB2312");
    }
    catch(Exception  usex)
    {
    return str;
    }
    } public static String UnicodeToISO88591(String str)
    {
    if(str == null) return str;
    try
    {
    return new String(str.getBytes("iso-8859-1"));
    }
    catch(Exception e)
    {
    return str;
    }
    } public static String ISO88591ToGB2312(String str)
    {
    if(str == null) return str;
    try
    {
    return new String(str.getBytes("iso-8859-1"),"GB2312");
    }
    catch(java.io.UnsupportedEncodingException e)
    {
    return str;
    }
    } public static String ISO88591ToGBK(String str)
    {
    if(str == null) return str;
    try
    {
    return new String(str.getBytes("iso-8859-1"),"GBK");
    }
    catch(java.io.UnsupportedEncodingException e)
    {
    return str;
    }
    } /*public static String UnicodeToGB2312(String str)
    {
    if(str == null) return str;
    try
    {
    char[] temp = str.getChars();
    byte[] b = new byte[temp.length];
    for(int i = 0; i < temp.length;i++)
    b[i] = (byte)temp[i];
    return new String(b,"GB2312");
    }
    catch(Exception e)
    {
    return str;
    }
    }*/ public static String EscapeHTMLTags(String input)
    {
    if(input == null || input.length() == 0)
    return input;
    StringBuffer buf = new StringBuffer(input.length() + 6);
    char ch = ' ';
    for(int i = 0;i<input.length();i++)
    {
    ch = input.charAt(i);
    if(ch == '<')
    buf.append("&lt;");
    else if(ch == '>')
    buf.append("&gt;");
    else if(ch == '\n')
    buf.append("<br>");
    else if(ch == ' ')
    buf.append("&nbsp;");
    else if(ch == '\'')
    buf.append("&acute");
    else
    buf.append(ch);
    }
    return buf.toString();
    } public static String toOriginal(String input)
    {
    if(input == null || input.length() ==0)
    return input;
    //String back = input;
    while(input.indexOf("<br>") >= 0)
    {
    int n = input.indexOf("<br>");
    input = input.substring(0,n) + input.substring(n + 4);
    }
    return input;
    } public static String Cut(String s)
    {
    if((s == null)||(s.length() < 5))
    return "N/A";
    int x = s.indexOf("<");
    if (x != -1)
    s = s.substring(0,x) + "...";
    return s;
    }
    }
      

  3.   

    补充上面,调用例子:
    String title = req.getParameter("title");
    title = ConvertCharSet.EscapeHTMLTags(title);//记录多行文本框中的回车,空格等信息
    title = ConvertCharSet.ISO88591ToGB2312(title);//字符转换
      

  4.   

    你用utf-8加字符集filter试一下看看。
    具体做法是:
    所有的.jsp文件都用utf-8
    写一个字符集filter,其实,tomcat中就有现存的。
    再将你的应用下的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>UTF-8</param-value>
        </init-param>
      </filter>
      

  5.   

    恩。。
    存入到数据库的时候要改变一下字符编码格式,一般转换成unicode
    读出来的时候再转换成GBK
      

  6.   

    因为request默认的字符集是iso-8859-1的
    所以jsp页面之间、jsp与servlet之间传递数据的时候最好像楼上lhbf(牧野)所说,加个设置request的characterEncoding的filter过滤一下至于与数据库的交互,我一般是在建立连接的时候设置clientEncoding,比如
    String ur1="jdbc:postgresql://localhost:5432/test?useUnicode=true&characterEncoding=GBK";是的,就是在后面添加了“?useUnicode=true&characterEncoding=GBK”这么一段Good Luck