我正在尝试将布尔值数组发送到 servlet。这是我到目前为止所做的,我很困惑:
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],“用户[i]”,用户。还是没找到。
在 servlet 上我有:
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]);
}
}
我在网上搜索了很多,找不到合适的。如果有人能帮助我,我将不胜感激。
谢谢