Skip to content Skip to sidebar Skip to footer

Problem Connecting To Servlet From Android Client

I am trying to connect to the Servlet (Tomcat localhost). Here is my code. ServletTest.java (the client) public class ServletTest extends Activity { private static final String

Solution 1:

You aren't executing the HTTP request. The URLConnection won't do that after writing to the request body and closing the stream as you seem to think. It will be executed only when you read anything from the response.

Do it after you write to the request body. E.g. get the response status and/or body.

intstatus= con.getResponseCode();

if (status == 200) {
    // Anything OK! Read if necessary response body. // It'll contain whatever you wrote by response.getWriter() in servlet.InputStreamresponse= con.getInputStream();
    // ...
}

See also:


Further, on Android you would also need to set user permission to connect the Internet. Add the following to the AndroidManifext.xml.

<uses-permissionandroid:name="android.permission.INTERNET" />

See also:

Post a Comment for "Problem Connecting To Servlet From Android Client"