vendredi 24 juin 2016

How can I return a String after client post from android to page JSP?

I'm new here. I am developing a web application for university project, where an android client send to a java server one image, and after that the server compares the image with those in a database and it have to send in response a String object to the client who invoked the server. How can i do it? I use to send the image from client, the library android-async-http, and it work great, but i don't know how to send a response. This is a partial code of the client:

public void makeHTTPCall(){
    prgDialog.setMessage("Server Connection..);
    AsyncHttpClient client=new AsyncHttpClient();
    client.post(ipAddress,params, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            prgDialog.hide();
            Snackbar.make(parentLayout,"Image uploaded.",Snackbar.LENGTH_LONG).show();
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            prgDialog.hide();
            if(statusCode==404){
                Snackbar.make(parentLayout,"Page not found.",Snackbar.LENGTH_LONG).show();
            }
            else if(statusCode==500){

                Snackbar.make(parentLayout,"Server problem.",Snackbar.LENGTH_LONG).show();
            }else{
                Snackbar.make(parentLayout,"Generic Error. code: "+statusCode,Snackbar.LENGTH_LONG).show();
            }
        }
    });


}

and here the code from server:

<%
String imgEncodedStr = request.getParameter("image");
String fileName = request.getParameter("filename");
System.out.println("Filename: "+ fileName);
if(imgEncodedStr != null){
    ManipolaImmagini.stringToImage(imgEncodedStr, fileName);
    System.out.println("Inside if");
    out.print("Image upload complete, Please check your directory");

} else{
    System.out.println("Inside else");
    out.print("Image is empty");    
}%>

Aucun commentaire:

Enregistrer un commentaire