Not getting any response from Servlet Page

In Android I have written a program and making a request on a button click to Servlet Page and in response it will execute message written on that servlet page but when I am running my project its not doing anything on that button click.

Here is my code,

public static final String URL = "http://10.0.2.2:8080/HttpGetServlet/HelloWorldServlet";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    button = (Button) findViewById(R.id.button);
    outputText = (TextView) findViewById(R.id.outputTxt);

    button.setOnClickListener(this);
}

public void onClick(View view) 
{
    GetXMLTask task = new GetXMLTask();
    task.execute(new String[] { URL });
}

private class GetXMLTask extends AsyncTask<String, Void, String> 
{
    @Override
    protected String doInBackground(String... urls) 
    {
        String output = null;
        for (String url : urls) 
        {
            output = getOutputFromUrl(url);
        }
        return output;
    }

    private String getOutputFromUrl(String url) 
    {
        String output = null;
        try 
        {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            output = EntityUtils.toString(httpEntity);
        } 
        catch (UnsupportedEncodingException e) 
        {
            e.printStackTrace();
        } 
        catch (ClientProtocolException e) 
        {
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }
        catch (Exception e)
        {
            Toast.makeText(getApplicationContext(), "Server Not Found!", Toast.LENGTH_LONG).show();
        }
        return output;
    }

    @Override
    protected void onPostExecute(String output) 
    {

        if(output==null)
            Toast.makeText(getApplicationContext(), "Server Not Found!", Toast.LENGTH_LONG).show(); 
        outputText.setText(output);
    }
}

If it can't find url then it should generate an Exception but i am catching exception then also nothing is happing.

Where i am wrong.

Please help.

Thanks.

Answers


       try 
            {
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();

                output = EntityUtils.toString(httpEntity);

                System.out.println(output); // here you can check the value of the output String.
            } 

If it has a value (it should) then your problem is on your user interface.

Maybe you need to configure the way that your interface gets the response.


Need Your Help

Google Script, Import HTML data

google-apps-script google-sheets

I'm trying to create a personal notifier whenever a certain website contains the word 'Indian' the script should email me.

Why on double click android client received data?

java android sockets

When I click the first time on login button, data send to server and server received data in return on first click data not show on android client screen. When I pressed login button again it again...