1:Eclipse首先导出JAVA开发的需要传输的实体类,导出成jar文件,导入到安卓的Eclipse中
2:hessian接口连接
static String url = ” http://192.168.1.18:8080/Hessian/HessianApiImpl";
private MyHessianProxyFactory factory = new MyHessianProxyFactory();
static HessianAPI hessian = null;
public static HessianAPI getHessianAPI(ClassLoader classLoader) {
MyHessianProxyFactory factory = new MyHessianProxyFactory();
factory.setConnectTimeOut(30000);
int c = 0;
while (true) {
c--;
try {
hessian = (HessianAPI) factory.create(HessianAPI.class, url,
classLoader);
if (hessian != null) {
break;
}
} catch (Exception e) {
hessian = null;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (c <= -4) {
break;
}
}
3:数据的获取
private HessianAPI hessian; //声明hessian接口文件,这个文件和服务器端的一样
String list_str="";
private Type type; //gson的type
private Gson gson = new Gson();
list_str = hessian.CustomerList(User.loginName, "",index,User.pagesize);
type = new com.google.gson.reflect.TypeToken<List<CustomerHessian>>(){}.getType();
list = gson.fromJson(list_str, type);
{"cCusCode":"01001","cCusName":"客户1"},{"cCusCode":"01002","cCusName":"客户2"}