title: how to pass data from servlet to android application
body: <pre><code>I have a form in android upon submit im inserting it into database using servlet i have to show to user that form was inserted successfully. this is my application
  
  
  
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.Statement;
  import java.util.ArrayList;
  
  
  
  /**
   *
   * @author trainee
   */
  public class form extends HttpServlet {
  
  String name;
  String password;
  Connection con = null;
  Statement stmt = null;
  /**
   * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt; methods.
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  
          /* TODO output your page here
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;Servlet form&lt;/title&gt;");  
          out.println("&lt;/head&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;h1&gt;Servlet form at " + request.getContextPath () + "&lt;/h1&gt;");
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
          */
  
  
  
  
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
  
     try
    {
  
    }
  
    catch(Exception ex)
    {
  
    }
  } 
  
  /** 
   * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    try
    {
       Class.forName("com.mysql.jdbc.Driver");
       con =DriverManager.getConnection ("jdbc:mysql://localhost:3306/Login","root", "");
       String nn=request.getParameter("name");
       String pass=request.getParameter("pass");
       String email=request.getParameter("email");
       stmt=con.createStatement();
       String query="insert into users values('"+nn+"','"+pass+"','"+email+"');";
       int v=stmt.executeUpdate(query);
       ArrayList&lt;String&gt; arr=new ArrayList&lt;String&gt;();
       arr.add("inserted");
  
  System.out.println("sent response back...");
  
    }
    catch(Exception ex)
    {
  
    }
  
  }
  
  /** 
   * Returns a short description of the servlet.
   * @return a String containing servlet description
   */
  @Override
  public String getServletInfo() {
      return "Short description";
  }// &lt;/editor-fold&gt;
  
  }
  </code></pre>
  
  <p>this is my android application</p>
  
  <pre><code>package org.me.loginandroid;
  
  import java.io.BufferedReader;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.io.*;
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  import org.json.JSONArray;
  import org.json.JSONObject;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import org.apache.http.client.methods.HttpGet;
  
  public class MainActivity extends Activity {
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          Button btn1 = (Button) findViewById(R.id.submit);
          btn1.setOnClickListener(listener_login);
      }
      private OnClickListener listener_login = new OnClickListener() {
  
          boolean check = false;
  
          public void onClick(View v) {
              EditText emailText = (EditText) findViewById(R.id.email);
              EditText passText = (EditText) findViewById(R.id.password);
              EditText nameText = (EditText) findViewById(R.id.uname);
  
              String name = nameText.getText().toString();
              String email = (emailText.getText().toString());
              String pass = (passText.getText().toString());
  
              String result = "";
              ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
              nameValuePairs.add(new BasicNameValuePair("name", name));
              nameValuePairs.add(new BasicNameValuePair("pass", pass));
              nameValuePairs.add(new BasicNameValuePair("email", email));
  
              try {
                  HttpClient httpclient = new DefaultHttpClient();
                  HttpPost httppost = new HttpPost("http://10.0.2.2:8084/Login/form");
                  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  HttpResponse response = httpclient.execute(httppost);
                  HttpEntity entity = response.getEntity();
                  InputStream is = entity.getContent();
  
                  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();
                  TextView lbl = (TextView) findViewById(R.id.lbl);
                  lbl.setText(result);
              } catch (Exception e) {
                  TextView tv = (TextView) findViewById(R.id.err);
                  tv.setText("Error parsing data " + e.toString());
                  System.out.println("Error parsing data " + e.toString());
              }
              //parse json data
              try {
                  boolean check=false;
                 ArrayList&lt;String&gt; arrays=new ArrayList&lt;String&gt;();
                 for(int i=0;i&lt;arrays.size();i++)
                 {
                     if(arrays.get(i).equals("Inserted"))
                     {
                          check=true;
                     }
                     else
                     {
                     }
                 }
                 if(check)
                 {
                     Intent myintent = new Intent(MainActivity.this, welcome.class);
                     startActivity(myintent);
                 }
                 else
                 {
                      TextView tv = (TextView) findViewById(R.id.err);
                      tv.setText("Data was not inserted properly");
                 }
  
  
              } catch (Exception e) {
                  //setContentView(R.layout.notify);
                  TextView tv = (TextView) findViewById(R.id.err);
                  tv.setText(e.toString());
                  System.out.println("log_tag" + "Error parsing data ");
  
              }
          }
      };
  }
  </code></pre>