1
我是新来的Web服务和编写代码以在Android中调用Jersey Web服务。但是我得到null作为PathParam的参数值。 请帮我解决我的代码问题。Jersey Web服务中的PathParam值null
下面是Android中的Web服务调用代码:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("content-type", "application/json");
JSONObject data = new JSONObject();
try {
data.put("email_id", strEmailId);
data.put("password", strPassword);
Log.d("1", data.toString());
HttpEntity entity;
StringEntity s = new StringEntity(data.toString());
entity = s;
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
}
这是Web服务代码:
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/dbconnect")
public String connectToDbTest(@PathParam("email_id") String email_id,@PathParam("password") String password) {
System.out.println(email_id+" "+password);
}
但我没有通过URL的路径值,我正在传递请求正文中的值。所以我不能让它像@Path(“/ dbconnect/{email_id}/{密码}”) – aaaaa 2013-03-01 05:55:21
mitratul答案是正确的。为了接收主体并保留实际路径,请更改方法的签名以接收JSON内容:'public String connectToDbTest(String content){...}'(放弃@ PathParam,因为它们使用错误)。从内容字符串中,您可以手动提取变量或使用JAXB等自动将JSON字符串转换为模型对象的框架。 – Florin 2013-03-01 15:22:12