android项目中有部下代码访问服务器,请问在服务器servlet中如何获得在android中传过去的键和值?public static boolean httpPostClient(String uri,Map<String,String> params)throws Exception{
boolean flag=false;
List<NameValuePair> list=new ArrayList<NameValuePair>();
if(params!=null&&!params.isEmpty()){
for(Map.Entry<String, String> map:params.entrySet()){
list.add(new BasicNameValuePair(map.getKey(), map.getValue()));
}
}
HttpClient client=new DefaultHttpClient();
HttpPost request=new HttpPost(uri);
HttpResponse response=client.execute(request);
UrlEncodedFormEntity entity=new UrlEncodedFormEntity(list,HTTP.UTF_8);
request.setEntity(entity);
if(response.getStatusLine().getStatusCode()==200){
flag=true;
}
System.out.println("flag="+flag);
return flag;
}准备传进去的参数map的键和值都不一样。例如:灯泡=2个,插座=3个。
请问如何在servlet中取得我传过去的键和值?

解决方案 »

  1.   

    好像可以用流可以接收数据,android客服端用URL来访问服务器,具体要查一下
      

  2.   

    这个经过测试,在servlet中直接使用request.getparameter("这里写上android端hashmap中的key即可"),或者用request.getparameters()得到所有传过来的key,然后根据key循环取值
      

  3.   

    request.getParameterMap()
    request.getParameterNames()
      

  4.   

    以前你是怎么从JSP取值的,现在也是一样的,都是HTTP协议
      

  5.   

    一样的啊 客户端遵守HTTP协议就行了 
      

  6.   

    get方法直接在URL中提交参数值对
    post在正文中提交参数值对
    这样服务器自然就会取得到