title: sending data in Post Method from Android Client to Java Servlet
body: <p>I implement client server code with java android. the problem is I couldn't be able to connect to servlet. Where is my problem? Here is my code:</p>
  
  <p><strong>android code</strong>: 
  .... </p>
  
  <pre><code>HttpClient client=new DefaultHttpClient();
  HttpPost getMethod=new HttpPost("http://" + Server + "/RestaurantServer/Login");
  
  try {
      // Add your data
  ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(3);
  nameValuePairs.add(new BasicNameValuePair("Mode", "Login"));
  nameValuePairs.add(new BasicNameValuePair("userName",txtusername.getText().toString() ));
      nameValuePairs.add(new BasicNameValuePair("password",txtpassword.getText().toString() ));
  
      getMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
      client.execute(getMethod);
  
  } catch (ClientProtocolException e) {
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>and server side:</p>
  
  <pre><code>protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
  
      try {
          String mode=request.getParameter("Mode");
          if ("Login".equals(mode)) {
              String userName= request.getParameter("userName");
              String password= request.getParameter("password");
              System.out.println("post method: "+userName + "! pass :"+password);
              user = new User(password,userName);
              if (UserDao.authenticate(user)==true)
                  out.write("Accept".toString());
              else
                  out.write("Wrong".toString());
          } else if ("Register".equals(mode)) {
              String userName= request.getParameter("userName");
              String password= request.getParameter("password");
              String name= request.getParameter("name");
              String email= request.getParameter("email");
              String address= request.getParameter("address");
              String phoneNumber= request.getParameter("phoneNumber");
              System.out.println("reg mod: "+userName + "! pass :"+password);
              user = new User(userName,password,name,email,address, phoneNumber);
  
              if (UserDao.addUser(user) == true)
                  out.write("Added");
              else
                  out.write("NotAdded");
          }
      } catch (Exception ex) {
          System.out.println("Problem in message reading");
      }
  }
  </code></pre>