ブール値の配列をサーブレットに送信しようとしています。これは私がこれまで行ってきたことであり、私はとても行き詰まっています:
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();
}
user[i], "user[i]", user. それでも見つかりませんでした。
そして私が持っているサーブレットで:
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]);
}
}
私はオンラインでたくさん検索しましたが、適切なものが見つかりませんでした。誰かがこれを手伝ってくれたら本当にありがたいです。
ありがとう