title: AngularJS POST to Server
body: <p>I have an angularJS form which posts data to a Java Servlet, but I am not seeing the request go through;  servlet "create" wasn't called.</p>
  
  <p>Here's my code:</p>
  
  <p>test.html</p>
  
  <p>
      
      
      
      
      
      
      </p>
  
  <pre><code>&lt;body&gt;
      &lt;form ng-controller="UserController"&gt;
  
          &lt;legend&gt;Create User&lt;/legend&gt;
          &lt;label&gt;Name&lt;/label&gt; 
          &lt;input type="text" id="name" name="name" ng-model="name" placeholder="User Name"&gt; 
  
          &lt;label&gt;Email&lt;/label&gt;
          &lt;input type="text" id="email" name="email" ng-model="email" placeholder="ur email here"&gt; 
  
          &lt;label&gt;Password&lt;/label&gt;
          &lt;input type="text" id="pwd" name="pwd" ng-model="pwd" placeholder="ur own pwd here"&gt;
  
          &lt;button ng-submit="createUser()" class="btn btn-primary"&gt;Register&lt;/button&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>script.js</p>
  
  <pre><code>function UserController($scope, $http) {
      $scope.user = {};
      $scope.createUser = function() {
          $http({
              method : 'POST',
              url : '/create',
              data : 'name=' + $scope.user.name + '&amp;email=' + $scope.user.email,
              headers : {
                  'Content-Type' : 'application/x-www-form-urlencoded'
              }
          })
      }
  </code></pre>
  
  <p>my servlet is as below,but it doesn't print "Post" an all.</p>
  
  <pre><code>public class FirstServlet extends HttpServlet
  {
  
      /**
       * 
       */
      private static final long   serialVersionUID    = 1L;
  
      @Override
      protected void doGet(HttpServletRequest req, HttpServletResponse resp)
              throws ServletException, IOException
      {
          System.out.println("Get");
      }
  
      @Override
      protected void doPost(HttpServletRequest req, HttpServletResponse resp)
              throws ServletException, IOException
      {
          System.out.println("Post");
      }
  }
  </code></pre>
  
  <p>The web server is jetty,and the web.xml as below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      version="2.4"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;createUser&lt;/servlet-name&gt;
          &lt;servlet-class&gt;servlet.FirstServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;0&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;createUser&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/create&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>