Good night,
I’m trying to send from a servlet written in Java data name in a JSON to an application in Android.
Not that I’m doing wrong but when it comes to mobile text comes a strange text.
Below I describe the code:
servlet:
if (opcion.equals("4")){//Devolver nombre, apellidos y DNI de Usuario
String usuario = request.getParameter("login");
Usuario user = facade.getUsuarioByLogin(usuario);
String nombre= user.getNombre();
String apellidos = user.getApellidos();
String dni = user.getDni();
System.out.println("El valor de Nombre es"+nombre);
response.setContentType("application/json");
JSONObject json = (JSONObject) JSONSerializer.toJSON( nombre );
//System.out.println("El valor de json"+json.toString());
out.println(json);
out.close();
}
Piece of Android application code that gets the JSON (I ignored the try catch to make the code more readable):
HttpClient cliente = new DefaultHttpClient();
HttpPost post = new HttpPost (url.toString());
ResponseHandler<String> handler = new BasicResponseHandler();
List<NameValuePair> elementos = ele;
post.setEntity(new UrlEncodedFormEntity(elementos));
HttpResponse respuesta = null;
respuesta = cliente.execute(post);
Log.i("Prueba", "El valor de respuesta es "+respuesta.toString());
I thought that respuesta should have the JSON that servlet sends me but it returns a text which does not contain the name
Do you see something you do wrong?
Greetings and thanks
You forgot to pass in the
ResponseHandlerinto theHttpClient#exeucte()method.Replace
by