I am trying to send array of boolean values to servlet. This is what I have done so far, and I am so stuck:
HttpClient client = new DefaultHttpClient();
String postURL = "http://APP_NAME.appspot.com/listenforrestclient";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
for (int i=0; i<arrBool.length; i++) {
arrBool[i] = r.nextBoolean();
String[] user = {"","","","","",""};
if (arrBool[i] == true) {
params.add(new BasicNameValuePair("user[i]", arrBool.toString()));
}
else if (arrBool[i] == false) {
params.add(new BasicNameValuePair("user[i]", arrBool.toString()));
}
}
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
System.out.printf("RESPONSE: ", EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
I tried to do just user[i], "user[i]", user. Still couldn't find it.
and on servlet I have:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
{
resp.setContentType("text/plain");
for (int i=0; i<mmaa.length; i++) {
mmaa = req.getParameterValues("user");
resp.getWriter().println(mmaa[i]);
}
}
I searched online a lot, couldn't find anything appropriate. I would really appreciate if someone would help me with this.
Thanks