从Android应用程序发送的JSON对象为空时,我想访问他的Java Servlet [英] The JSON object sent from android application is null when i want to access him in java servlet

查看:168
本文介绍了从Android应用程序发送的JSON对象为空时,我想访问他的Java Servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在Android的应用程序和我发送一个JSON对象到一个Java servlet。

I am writing an application in android and i am sending a json object to a java servlet.

这是Android code:

This is the android code:

HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(URL);
JSONObject jsonObjectToPass  = returnJsonStringObject();
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new BasicNameValuePair("jsonGPSParameter",jsonObjectToPass.toString()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams);
entity.setContentEncoding(HTTP.UTF_8);
entity.setContentType("application/json");   
post.setHeader("Content-type", "application/json");
post.setEntity(entity);
response = httpClient.execute(post);

这是的Java Servlet code

This is the java servlet code

request.getParameter("jsonGPSParameter");

的问题是,在getParameter()方法返回空。
我不是能够发现问题。
如果someoane可以帮助我这将是一个很大的帮助。

The problem is that the getParameter() method return null. Im not be able to spot the problem. If someoane can help me it would be a great help.

感谢

推荐答案

对于code适当的工作,我必须删除从旁边的Andr​​oid code线:

For the code to work proper i have to remove the next to lines from android code:

entity.setContentType("application/json");   
post.setHeader("Content-type", "application/json"); 

这篇关于从Android应用程序发送的JSON对象为空时,我想访问他的Java Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆