My guess is you are using the emulator here. To the emulator,
"localhost" will refer to the emulator itself. It is its own virtual
device, you may consider it its own entity on the network, so you'll
need to use a proper hostname or IP address for the servlet you want
to access.

Cheers,
Justin
Android Team @ Google

On Jul 22, 6:47 am, Ahmed BEJAOUI <[email protected]> wrote:
> Hello every body, and excuse me for my poor English .
>
> I'm trying de build an activity which connect to a servlet. But the command
> "execute (httpGet)" doesn't work!! i write the permission of internet in the
> manifest.xml, but it doesn't work!!
> heres my code its supposed to connect to the servlet: and thank you
>
> import java.io.InputStream;
>
> import org.apache.http.HttpEntity;
> import org.apache.http.HttpResponse;
> import org.apache.http.client.HttpClient;
> import org.apache.http.client.ResponseHandler;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.impl.client.BasicResponseHandler;
> import org.apache.http.impl.client.DefaultHttpClient;
> import org.xml.sax.InputSource;
> import org.xml.sax.XMLReader;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.util.Log;
> import android.widget.EditText;
>
> public class Connect extends Activity {
>     /** Called when the activity is first created. */
>
>     private String adresse = new 
> String("http://localhost:8080/Test_tomcat/Testt";);
>     private EditText mTitleText;
>
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>         mTitleText = (EditText) findViewById(R.id.message);
>         connect(adresse);
>     }
>
>     public void connect(String url){
>         try {
>             HttpClient httpclient = new DefaultHttpClient();
>
>             // Prepare a request object
>             HttpGet httpget = new HttpGet(url);
>
>             // Execute the request
>             HttpResponse response;
>             try {
>
>                 response = httpclient.execute(httpget);
>
>                  mTitleText.append("connexion");
>
>                 // Get hold of the response entity
>                 HttpEntity entity = response.getEntity();
>                 // If the response does not enclose an entity, there is no
> need
>                 // to worry about connection release
>
>                 if (entity != null) {
>                     mTitleText.append(response.getStatusLine().toString());
>                 }
>                 }catch (Exception e) {mTitleText.append("connexion");
>                 }
>
>             httpclient.getConnectionManager().shutdown();
>
>         } catch (Exception e) {
>             Log.e("Connect", "exception au niveau de l'adresse");
>
>         }
>
>
>
> }
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to