编码是utf-8时,页面中文肯定会出现乱码,因为中文编码是gb2312的,如果使用utf-8显示中文,必须把中文转换为unicode码才可以,不能直接写中文,也就是必须转成/u#### 的unicode码

解决方案 »

  1.   

    用<%@ page contentType="text/html; charset=UTF-8" %>时,中文输入为什么会出现乱码。一般这种情况都应该怎么解决呢
      

  2.   

    一般情况下是把所有的中文放入资源文件,然后把资源文件统一编为unicode码这样可以达到国际化
      

  3.   

    看你的代码使用的是jsp吧java里面有个工具native2ascii.exe,就是用来转换unicode码的,就在%JAVAHOME%/bin/下面
      

  4.   

    Sorry to bother you a lot.
    我所做的是一个portal项目,有很多页面,和这个工具接合起来用不太好吧。有没有一种什么转换函数可以把他们转换过来。
      

  5.   

    这个我手头没有,你去google搜一下吧,呵呵,不好意思@_@
      

  6.   

    我在网上找了个函数 
    static public String convertUTF8String2Unicode(String instr)
    throws IOException {
    //byte[] strbytes = instr.getBytes();
    int charindex = instr.length();
    int actualValue;
    int inputValue;
    StringBuffer sbtemp = new StringBuffer();for (int i = 0; i < charindex;) {actualValue = -1;
    inputValue = instr.charAt(i++);inputValue &= 0xff;   if ((inputValue & 0x80) == 0) {
           actualValue = inputValue;
       }
       else if ((inputValue & 0xF8) == 0xF0) {
           actualValue = (inputValue & 0x1f) << 18;       int nextByte = instr.charAt(i++) & 0xff;
           if ((nextByte & 0xC0) != 0x80)
               throw new IOException("Invalid UTF-8 format");
           actualValue += (nextByte & 0x3F) << 12;       nextByte = instr.charAt(i++) & 0xff;
           if ((nextByte & 0xC0) != 0x80)
               throw new IOException("Invalid UTF-8 format");
           actualValue += (nextByte & 0x3F) << 6;       nextByte = instr.charAt(i++) & 0xff;
           if ((nextByte & 0xC0) != 0x80)
           throw new IOException("Invalid UTF-8 format");
           actualValue += (nextByte & 0x3F);
           }
           else if ((inputValue & 0xF0) == 0xE0) {
           actualValue = (inputValue & 0x1f) << 12;       int nextByte = instr.charAt(i++) & 0xff;
           if ((nextByte & 0xC0) != 0x80)
               throw new IOException("Invalid UTF-8 format");
           actualValue += (nextByte & 0x3F) << 6;   nextByte = instr.charAt(i++) & 0xff;
       if ((nextByte & 0xC0) != 0x80)
           throw new IOException("Invalid UTF-8 format");
       actualValue += (nextByte & 0x3F);
       }
       else if ((inputValue & 0xE0) == 0xC0) {
       actualValue = (inputValue & 0x1f) << 6;   int nextByte = instr.charAt(i++) & 0xff;
       if ((nextByte & 0xC0) != 0x80)
       throw new IOException("Invalid UTF-8 format");
       actualValue += (nextByte & 0x3F);
       }
       sbtemp.append((char) actualValue);
       }   return sbtemp.toString();
       }