android如何获取服务器的对象,android 服务端如何获取客户端传递来的数据(在线 100分)...

客户端代码

String url =”http://192.168.1.160:8080/MDXT/padlogin.action”;

HttpPost request = new HttpPost(url);

// 先封装一个 JSON 对象

JSONObject param = new JSONObject();

try {

param.put(“name”, “rarnu”);

param.put(“password”, “123456”);

// 绑定到请求 Entry

StringEntity se = new StringEntity(param.toString());

request.setEntity(se);

// 发送请求

HttpResponse httpResponse = new DefaultHttpClient().execute(request);

JSONObject result = null;

int code=httpResponse.getStatusLine().getStatusCode();

if (code == 200) {

// 得到应答的字符串,这也是一个 JSON 格式保存的数据

String retSrc = null;

retSrc = EntityUtils.toString(httpResponse.getEntity(),”utf-8″);

JSONObject jtmpJsonObject = new JSONObject(retSrc);

String str = jtmpJsonObject.getString(“username”);// 此处”dataMap”与服务器关联

System.out.println(“用户名+**********************”+str);

}

} catch (JSONException e) {

e.printStackTrace();

}

注:想知道 request.setEntity(se);  我这样设置的值    怎么在服务端获取,

如果是说让我用http://192.168.1.160:8080/MDXT/padlogin.action?usern=””ss’&pas=””xx””  这种方式的话 那就算了,因为我主要是想知道数据在服务器端是怎么接受的

服务端代码

服务端本人采用的是struts2

struts2的配置文件 就不贴出来了

现在服务器端的数据 我在客户端能接收到  但是就是不知道怎么接受客户端传递来的数据

public String loginPad(){

HttpServletRequest req=ServletActionContext.getRequest();

HttpServletResponse resp=ServletActionContext.getResponse();

LoginDao login = new LoginDao();

JSONObject json = new JSONObject();

System.out.println(“lai ……………………..”);

resp.setCharacterEncoding(“GBK”);

try {

String data = req.getParameter(“name”);

json.put(“username”, “by”);

json.put(“mdname”, “xxx”);

System.out.println(“lai ……………………..”+data);

//返回json 格式的数据

resp.getWriter().write(json.toString());

//MenDianInfo mdInfo = login.isExistedUser(username, password);

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

在线等,谢谢各位大神

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值