萍聚社区-德国热线-德国实用信息网

 找回密码
 注册

微信登录

微信扫一扫,快速登录

萍聚头条

查看: 992|回复: 1

1-1-16-6-5 还是汉字问题,我看了精华区的,不管用

[复制链接]
发表于 2003-5-12 21:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册 微信登录

x
发信人: weffen (wef), 信区: Java
标  题: Re: 还是汉字问题,我看了精华区的,不管用
发信站: BBS 水木清华站 (Thu May  4 11:10:28 2000)

首先,如果你是用post方法的话,就localize就okay了:

  1.   public static String localize(String original, String local){

  2.     if(local==null)
  3.       local = "ISO-8859-1";
  4.     try{
  5.       return (new String(original.getBytes("ISO-8859-1"),local));
  6.     }
  7.     catch(Exception e){
  8.       System.out.println(e.getMessage());
  9.       return original;
  10.     }
  11.   }
  12. 如果用GET方式的话,尤其是自己写 servlet?param=chinese的话,就有点麻烦:
  13. 首先,把参数的中文Unicode化:
  14.   public static String unicodize(String original, String local){

  15.     if(local==null)
  16.       local = "ISO-8859-1";
  17.     try{
  18.       return (new String(original.getBytes(local),"ISO-8859-1"));
  19.     }
  20.     catch(Exception e){
  21.       System.out.println(e.getMessage());
  22.       return original;
  23.     }
  24.   }
复制代码

然后,URLEncode.encode()那个unicodize的中文,接收的时候再localize,就变成你要的
东西了

【 在 joywing (joywing) 的大作中提到: 】
: 我用servlet取得表单中的汉字
: 如何将他们显示在浏览器上


--
※ 来源:·BBS 水木清华站 smth.org·[FROM: 166.111.144.186]
Die von den Nutzern eingestellten Information und Meinungen sind nicht eigene Informationen und Meinungen der DOLC GmbH.
 楼主| 发表于 2003-5-12 21:38 | 显示全部楼层
  1. 发信人: javafancy (love java), 信区: Java
  2. 标  题: Re: 还是汉字问题,我看了精华区的,不管用
  3. 发信站: BBS 水木清华站 (Thu May  4 11:51:50 2000)

  4. 也可以用这个方法
  5. byte[] temp_t;
  6. String temp_p;
  7. temp_p=request.getParameter("message");
  8. temp_t=temp_p.getBytes("ISO8859-1");
  9. String temp=new String(temp_t);
  10. 原理和weffen大虾的一样

  11. 【 在 weffen (wef) 的大作中提到: 】
  12. : 首先,如果你是用post方法的话,就localize就okay了:
  13. :   public static String localize(String original, String local){
  14. :     if(local==null)
  15. :       local = "ISO-8859-1";
  16. :     try{
  17. :       return (new String(original.getBytes("ISO-8859-1"),local));
  18. :     }
  19. :     catch(Exception e){
  20. :       System.out.println(e.getMessage());
  21. :       return original;
  22. :     }
  23. :   }
  24. : 如果用GET方式的话,尤其是自己写 servlet?param=chinese的话,就有点麻烦:
  25. : 首先,把参数的中文Unicode化:
  26. :   public static String unicodize(String original, String local){
  27. :     if(local==null)
  28. :       local = "ISO-8859-1";
  29. :     try{
  30. :       return (new String(original.getBytes(local),"ISO-8859-1"));
  31. :     }
  32. :     catch(Exception e){
  33. :       System.out.println(e.getMessage());
  34. :       return original;
  35. :     }
  36. :   }
  37. : 然后,URLEncode.encode()那个unicodize的中文,接收的时候再localize,就变成你要的
  38. : 东西了
复制代码
Die von den Nutzern eingestellten Information und Meinungen sind nicht eigene Informationen und Meinungen der DOLC GmbH.
您需要登录后才可以回帖 登录 | 注册 微信登录

本版积分规则

手机版|Archiver|AGB|Impressum|Datenschutzerklärung|萍聚社区-德国热线-德国实用信息网

GMT+1, 2025-2-12 08:32 , Processed in 0.058804 second(s), 19 queries , MemCached On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表