Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Java½âÎöÍøÂçÊý¾ÝÁ÷µÄÈýÖÖÌØÊâ·½·¨

UTF8ת»»³ÉGB2312 µ±ÎÒÃÇÔÚ»ùÓÚHTTPЭÒéµÄJSP»òServletµÄÓ¦ÓÃÖлñÈ¡Êý¾Ý»ò·¢ËÍÇëÇóʱ£¬JVM»á°ÑÊäË͵ÄÊý¾Ý±àÂë³ÉUTF8¸ñʽ¡£Èç¹ûÎÒÃÇÖ±½Ó´ÓHTTPÁ÷ÖÐÌáÈ¡ÖÐÎÄÊý¾Ý£¬ÌáÈ¡µÄ½á¹ûΪ“????”£¨¿ÉÄܸü¶àÎʺţ©£¬Îª×ª»»³ÉÎÒÃÇÄܹ»Àí½âµÄÖÐÎÄ×Ö·û£¬ÎÒÃÇÐèÒª°ÑUTF8ת»»³ÉGB2312£¬½èÖúISO-8859-1±ê×¼±àÂëÄܹ»ÇáÒ×µÄʵÏÖ£¬ÏÂÃæµÄ´úÂëʵÏÖÁËÕâÒ»¹¦ÄÜ£º
byte [] b;
String utf8_value;
utf8_value = request.getParameter("NAME");//´ÓHTTPÁ÷ÖÐÈ¡"NAME"µÄUTF8Êý¾Ý
b = utf8_value.getBytes("8859_1"); //ÖмäÓÃISO-8859-1¹ý¶É
String name = new String(b, "GB2312"); //ת»»³ÉGB2312×Ö·û
¡¡¡¡ÔÚÖªµÀÁ÷³¤¶ÈµÄÇé¿öϽ«ÊäÈëÁ÷ת»»³É×Ö½ÚÊý×é JavaÖеÄÊäÈëÁ÷³éÏóÀàInputStreamÓÐint read(byte[] b, int off, int len)·½·¨£¬²ÎÊýÖÐbyte[] bÊÇÓÃÀ´´æ·Å´ÓInputStreamÖжÁÈ¡µÄÊý¾Ý,int offÖ¸¶¨Êý×ébµÄÆ«ÒƵØÖ·£¬Ò²¾ÍÊÇÊý×ébµÄÆðʼϱ꣬int lenÖ¸¶¨ÐèÒª¶ÁÈ¡µÄ³¤¶È£¬·½·¨·µ»Øʵ¼Ê¶ÁÈ¡µÄ×Ö½ÚÊý¡£¸ÕѧJavaµÄÅóÓÑ¿ÉÄÜҪ˵£ºÏȶ¨ÒåÒ»¸öÓëÁ÷³¤¶ÈµÈ³¤µÄ×Ö½ÚÊý×飬µ÷ÓÃread·½·¨£¬Ö¸¶¨ÆðʼϱêΪ0£¬Ö¸¶¨¶ÁÈ¡³¤¶ÈÓëÊý×鳤¶ÈµÈ³¤£¬²»ÊÇÒ»ÏÂ×Ó¿ÉÒÔ¶Á³öÀ´ÁËÂð£¿ËµµÄû´í£¬±ÊÕßÔø¾­Ò²ÊÔ×ÅÕâÑù¶ÁÈ¡Êý¾Ý£¬µ«ºóÀ´·¢ÏÖÔÚ¶ÁÈ¡ÍøÂçÊý¾ÝʱºÜ²»°²È«£¬ÎÒÃÇÏëÏëÔÚÍøÂçÉÏ»ñÈ¡Êý¾Ý¿ÉÄܲ¢Ã»ÄÇôÁ÷³©£¬Êý¾ÝÁ÷µÄ´«ËÍ¿ÉÄÜ»á¶Ï¶ÏÐøÐø£¬ËùÒÔ²¢²»Äܱ£Ö¤Ò»´Î¾ÍÄܶÁÈ¡È«²¿Êý¾Ý£¬ÌرðÊÇÔÚ¶ÁÈ¡´óÈÝÁ¿Êý¾Ýʱ¸üÊÇÈç´Ë£¬ËùÒÔÎÒÃDZØÐëÔÚ¶ÁÈ¡Êý¾Ýʱ¼ì²âʵ¼Ê¶Áµ½µÄ³¤¶È£¬Èç¹ûûÓжÁÍêÒÑÖª³¤¶ÈµÄÊý¾Ý¾ÍÓ¦¸ÃÔٴζÁÈ¡£¬ÒÔ´ËÑ­»·¼ì²â£¬Ö±µ½Êµ¼Ê¶ÁÈ¡µÄ³¤¶ÈÀÛ¼ÓÓëÒÑÖªµÄ³¤¶ÈÏàµÈ£¬ÏÂÃæµÄ´úÂëʵÏÖÁËÕâÒ»¹¦ÄÜ£º
ServletInputStream inStream = request.getInputStream(); //È¡HTTPÇëÇóÁ÷
int size = request.getContentLength(); //È¡HTTPÇëÇóÁ÷³¤¶È
byte[] buffer = new byte[size]; //ÓÃÓÚ»º´æÿ´Î¶ÁÈ¡µÄÊý¾Ý
byte[] in_b = new byte[size]; //ÓÃÓÚ´æ·Å½á¹ûµÄÊý×é
int count = 0;
int rbyte = 0;
while (count < size) { //Ñ­»·¶ÁÈ¡
¡¡rbyte = inStream.read(buffer); //ÿ´Îʵ¼Ê¶ÁÈ¡³¤¶È´æÓÚrbyteÖÐ
¡¡for(int i=0;i;)
¡¡¡¡in_b[count + i] = buffer[i];
}
count += rbyte;
}
¡¡¡¡ÔÚ²»ÖªµÀÁ÷³¤¶ÈµÄÇé¿öϽ«ÊäÈëÁ÷ת»»³É×Ö½ÚÊý×é Ç°Ãæ½éÉÜÁËÒÑÖªÁ÷³¤¶ÈµÄÇé¿öϵÄת»»·½·¨£¬ÄÇôµ±ÎÒÃDz»ÖªµÀÁ÷Óж೤ʱ£¬Ò²¾ÍÊÇ˵²»ÄÜÈ·¶¨×ª»»ºóµÄ×Ö½ÚÊý×éÓжà´óʱ£¬¸ÃÔõô´¦ÀíÄØ£¿±ÊÕ߲鿴ÁËJDKÎĵµÖ®ºó·¢ÏÖ


Ïà¹ØÎĵµ£º

½âÎöJavaÀàºÍ¶ÔÏóµÄ³õʼ»¯¹ý³Ì

ÀàµÄ³õʼ»¯ºÍ¶ÔÏó³õʼ»¯ÊÇ JVM ¹ÜÀíµÄÀàÐÍÉúÃüÖÜÆÚÖзdz£ÖØÒªµÄÁ½¸ö»·½Ú£¬Google ÁËÒ»±éÍøÂ磬ÓйØÀà×°ÔØ»úÖƵÄÎÄÕµ¹ÊDz»ÉÙ£¬È»¶øÀà³õʼ»¯ºÍ¶ÔÏó³õʼ»¯µÄÎÄÕ²¢²»¶à£¬ÌرðÊÇ´Ó×Ö½ÚÂëºÍ JVM ²ã´ÎÀ´·ÖÎöµÄÎÄÕ¸üÊÇÏÊÓÐËù¼û¡£
±¾ÎÄÖ÷Òª¶ÔÀàºÍ¶ÔÏó³õʼ»¯È«¹ý³Ì½øÐзÖÎö£¬Í¨¹ýÒ»¸öʵ¼ÊÎÊÌâÒýÈ룬½«Ô´´úÂëת»»³É JVM ×Ö½ÚÂëºó£¬ ......

Java ¼¯ºÏ Ḭ̈߳²È«


Ḭ̈߳²È«µÄ¼¯ºÏ°üº¬2¸öÎÊÌâ   
1.¶àÏ̲߳¢·¢ÐÞ¸ÄÒ» ¸ö ¼¯ºÏ Ôõô°ì£¿   
2.Èç¹ûµü´úµÄ¹ý³ÌÖР¼¯ºÏ ±»ÐÞ¸ÄÁËÔõô°ì£¿   
    a.Ò»¸öÏß³ÌÔÚµü´ú£¬ÁíÒ»¸öÏß³ÌÔÚÐÞ¸Ä   
    b.ÔÚͬһ¸öÏß³ÌÄÚÓÃͬһ¸öµü´úÆ÷¶ ......

´«ÖDz¥¿Í2009 12 23 Ò»¡¢java»ù´¡¼ÓÇ¿(1)

½ñÌìÊÇÉϿεĵÚÒ»Ì죬еÄÀÏʦ¡¢ÐµÄͬѧ¡¢ÐµĻ·¾³£¬Ò»Çж¼ÊÇеģ¬´Ó½ñÌìÆðÎÒ½«ÔÚÖÚ¶àjava´óʦµÄϤÐĸ¨µ¼Ï½øÐÐΪÆÚËĸöÔµÄħ¹íѧϰ£¬ÒÔÇóʹ×Ô¼ºÓÐÒ»¸öÍÑÌ¥»»¹ÇµÄ±ä»¯£¬Îª×Ô¼º½«À´µÄ¹¤×÷ºÍÉú»îµì¶¨Ò»¸ö¼áʵµÄ»ù´¡¡£
“¹¤ÓûÉÆÆäÊ£¬±ØÏÈÀûÆäÆ÷”£¬¶ÔÓÚMyEclipseµÄѧϰºÍʹÓþÍÏÔµÃÓÈΪÖØÒª£º
  &nb ......

javadz̸


———————————————————   ­
  ¸¶³öµÄŬÁ¦·Ç³£ÈËËùÄÜÏëÏó   ­
  ——————————— ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ