0

i want to sent very large data from Server to client, the server is tomcat Java and the client is android application , i am working with servlets

server servlet

protected void doPost(HttpServletRequest request,
                      HttpServletResponse response) throws ServletException,
                                                           IOException {
    ServletOutputStream out = response.getOutputStream();
    CellDatabase cDB = new CellDatabase();
    String[] cells = cDB.getAllCells();
    for (int i = 0; i < cells.length; i++)
        out.write(cells[i].getBytes());
    out.flush();
}

my question is : how can i got that data on android , because i didn't find something like

response.getOutputStream();

android

HttpClient client = new DefaultHttpClient();
website = new URI(
        "http://10.0.2.2:8080/LocalizedBasedComptitionServer/GetCells");
HttpPost request = new HttpPost();
request.setURI(website);
HttpResponse response = client.execute(request);
1

1 Answer 1

3

this may help you

public static String getData(String url) {

    System.out.println("Connecting to service URL : " + url);
    InputStream is = null;
    String result = "";
    // http post
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();

    } catch (Exception e) {
    }

    // convert response to string
    try {
        BufferedReader reader =
            new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result = sb.toString();
    } catch (Exception e) {
    }

    return result;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.