XFire中文乱码问题

 

下面的例子是经历过测试的,没有问题。 

由于我在调用webservice之前,通过filter已经把字符集编码变成GBK,而xfire 数据传输原理,它是通过ISO-8859-1的编码格式转化成GBK,所以很多的时候转换过后的字符集是GBK的乱码! 

 

import java.io.UnsupportedEncodingException; 

 

 

public class test { 

 

public static void main(String arg[]){ 

try { 

/** 

* xfire 数据传输原理,它是通过ISO-8859-1的编码格式转化成GBK 

* 所以,如果之前的编码格式是GBK的话相当于 

* getBytes("ISO-8859-1"),"GBK")也就是把中文直接以ISO-8859-1的格式,转化成了GBK 

* 所以传到服务器的时候就变成了乱码 

* 所以在服务器端调用的时候就需要getBytes("GBK"),"utf-8" 

*  String xmlStr_tp = new String(xmlStr.getBytes("GBK"),"UTF-8");

*/ 

String s ="你好,我很满意"; 

String s1 = new String(s.getBytes("GBK"),"utf-8"); 

//哈哈 

String s3 = new String(s.getBytes("GBK"),"utf-8"); 

String s5 = new String(s.getBytes("utf-8"),"ISO-8859-1"); 

String s6 = new String(s5.getBytes("ISO-8859-1"),"GBK"); 

String s4 = new String(s.getBytes("utf-8"),"GB2312"); 

System.out.println("s1==="+s1); 

System.out.println("s4==="+s4); 

System.out.println("s3==="+s3); 

System.out.println("s6==="+s6); 

String s2 = new String(new String(s.getBytes("GBK"),"ISO-8859-1").getBytes("ISO-8859-1"),"GBK"); 

System.out.println("s2==="+s2); 

 

 

String   tempStr   =   "中文";//准备转换的字符   

String   result   =java.net.URLEncoder.encode(tempStr,"utf-8"); 

System.out.println("result==="+result); 

 

// System.out.println("ISO-GBK" +new String(haha.getBytes("GBK"),"ISO-8859-1")); 

// System.out.println("ISO-GBK" +new String(haha.getBytes("ISO-8859-1"),"GBK")); 

} catch (UnsupportedEncodingException e) { 

// TODO Auto-generated catch block 

e.printStackTrace(); 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.xfire.core.client; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; import com.xfire.core.entity.UserInfo; import com.xfire.core.service.IUserInfoService; /** *@author jilongliang *@Date 2012-3-5 * */ public class UserInfoClient { public static void main(String[] args) { getServiceList(); setServiceList(); } static String url = "http://localhost:8081/xfire/services/UserInfo"; /** * */ public static void getServiceList() { Service service = new ObjectServiceFactory() .create(IUserInfoService.class); try { IUserInfoService iAddressService = (IUserInfoService) new XFireProxyFactory() .create(service, url); List list = (ArrayList) iAddressService .getAddressList(); System.out.println("一共多少条数据:" + list.size()); for (Iterator iter = list.iterator(); iter.hasNext();) { UserInfo a = iter.next(); System.out.println(a); } } catch (MalformedURLException e) { e.printStackTrace(); } } public static void setServiceList() { Service service = new ObjectServiceFactory() .create(IUserInfoService.class); try { IUserInfoService iAddressService = (IUserInfoService) new XFireProxyFactory() .create(service, url); List listAdd = new ArrayList(); UserInfo address = new UserInfo(); address.setIdentifier(1); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress("廣東陽春"); address.setPostCode("1111111"); address.setExist(false); address.setArrary(new String[] { "22", "23", "24" }); listAdd.add(address); address.setIdentifier(2); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress(

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值