java/jsp中 中文问题详解_MySQL

WBOY
풀어 주다: 2016-06-01 14:08:35
원래의
939명이 탐색했습니다.

预备知识:
 1.字节和unicode
  Java内核是unicode的,就连class文件也是,但是很多媒体,包括文件/流的保存方式
  是使用字节流的。 因此Java要对这些字节流经行转化。char是unicode的,而byte是字节.
  Java中byte/char互转的函数在sun.io的包中间有。其中ByteToCharConverter类是中调度,
  可以用来告诉你,你用的Convertor。其中两个很常用的静态函数是
   public static ByteToCharConverter getDefault() ;
   public static ByteToCharConverter getConverter(String encoding);
  如果你不指定converter,则系统会自动使用当前的Encoding,GB平台上用GBK,EN平台上用
  8859_1
  
  我们来就一个简单的例子:
     "你"的gb码是:0xC4E3 ,unicode是0x4F60

     你用:
     --encoding="gb2312";
     --byte b[]={(byte)'u00c4',(byte)'u00E3'};
     --convertor=ByteToCharConverter.getConverter(encoding);
     --char [] c=converter.convertAll(b);
     --for(int i=0;i      --{
     -- System.out.println(Integer.toHexString(c[i]));
     --}
     --打印出来是0x4F60
     --但是如果使用8859_1的编码,打印出来是
     --0x00C4,0x00E3
     ----例1
     反过来:
     --encoding="gb2312";
        char c[]={'u4F60'};
        convertor=ByteToCharConverter.getConverter(encoding);
     --byte [] b=converter.convertAll(c);
     --for(int i=0;i      --{
     -- System.out.println(Integer.toHexString(b[i]));
     --}
      --打印出来是:0xC4,0xE3
      ----例2
      --如果用8859_1就是0x3F,?号,表示无法转化      --
      很多中文问题就是从这两个最简单的类派生出来的。而却有很多类  
  不直接支持把Encoding输入,这给我们带来诸多不便。很多程序难得用encoding
  了,直接用default的encoding,这就给我们移植带来了很多困难
  --
  2.UTF-8
  --UTF-8是和Unicode一一对应的,其实现很简单
  --
   -- 7位的Unicode: 0 _ _ _ _ _ _ _
  --11位的Unicode: 1 1 0 _ _ _ _ _ 1 0 _ _ _ _ _ _
  --16位的Unicode: 1 1 1 0 _ _ _ _ 1 0 _ _ _ _ _ _ 1 0 _ _ _ _ _ _
  --21位的Unicode: 1 1 1 1 0 _ _ _ 1 0 _ _ _ _ _ _ 1 0 _ _ _ _ _ _ 1 0 _ _ _ _ _ _
  --大多数情况是只使用到16位以下的Unicode:
  --"你"的gb码是:0xC4E3 ,unicode是0x4F60
  --我们还是用上面的例子
  --  --例1:0xC4E3的二进制:

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!