Pessoal estou com dúvida de como eu recebo um JSONObject em um Servlet?
Eu faço esse Post para um Servlet
JSONObject jsonObj = new JSONObject();
jsonObj.put("username", username);
jsonObj.put("apikey", apikey);
// Create the POST object and add the parameters
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
entity.setContentType("application/json");
httpPost.setEntity(entity);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpPost);
Como eu receberia esse Post lá no Servlet?
O request.getParameter() não funciona…
Servlet implementation class Servlet
*/ @WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
@see HttpServlet#HttpServlet()
*/
public Servlet() {
super();
// TODO Auto-generated constructor stub
}
JSONObject jsonObj = new JSONObject();
jsonObj.put("username", username);
jsonObj.put("apikey", apikey);
HttpClient client = new DefaultHttpClient();
System.out.println(jsonObj.toString());
// Create the POST object and add the parameters
HttpPost httpPost = new HttpPost("http://localhost:8080/infra-mon/Servlet");
StringEntity entity = new StringEntity(jsonObj.toString());
entity.setContentType("application/json");
httpPost.setEntity(entity);
HttpResponse response2 = client.execute(httpPost);
}
out.flush();
out.close();
}
}
[/code]
Estou só querendo testar a comunicação entre 2 Servlets via JSON, porem não estou conseguindo, então queria ver se alguem pudesse me indicar aonde estou errando.