title: Send Data from client angular2 to server spring 'POST'
body: <p>I dont have any error but I get data null in the server side
  can you help for by giving an example thks</p>
  
  <p>this is my client service</p>
  
  <pre><code>import {Injectable, Inject} from "angular2/core";
  import {Http, Headers} from "angular2/http";
  import 'rxjs/add/operator/map';
  import {User} from "../User/User";
  
  
  @Injectable()
  export class loginService {
  
      constructor(private _http:Http) {
  
      }
  
      login(user) {
  
          // var creds = "username=" + "khalil" + "&amp;password=" + 3;   .map(res=&gt;res.text());
          var headers = new Headers();
          headers.append('Content-Type', 'application/json');
          return this._http.post('http://localhost:8080/login', user, {
                  headers: headers
              })
              .map(res=&gt;res.json());
  
      }
  </code></pre>
  
  <p>this is my component where I call login method</p>
  
  <pre><code>import {Component, Inject} from 'angular2/core';
  import {Router} from "angular2/router";
  import {loginService} from "./login.service";
  import {HTTP_PROVIDERS, Http} from "angular2/http";
  import {User} from "../User/User";
  import {ControlGroup, FormBuilder, Validators, Control} from "angular2/common";
  
  @Component({
      selector: 'login',
      templateUrl: '../dev/login/login.html',
      providers: [HTTP_PROVIDERS, loginService]
  })
  
  export class loginComponent {
      public _user:User;
      loginForm:ControlGroup;
  
      constructor(private _router:Router,
                  private _loginService:loginService,
      private _formBuilder:FormBuilder) {
  
  
          this._user = {
              firstName: '',
              lastName: '',
              tel: '',
              email: '',
              creationDate: new Date(),
              compteMatriculaire: '',
              enabled: false,
              password: '',
              structure: ''
          };
  
      }
  
      login() {
          console.log("email"+this._user.email);
          this._loginService.login(this._user).subscribe(
              (data:User) =&gt; {
                 this._user = data;
              },
              error =&gt; alert('Erreur ' + error),
              () =&gt; {
                  console.log("finished  " + this._user.email + "   " + this._user.password);
                  //this._router.navigate(['Home']);
              }
          );
      }
  </code></pre>
  
  <p>this is my form page </p>
  
  <pre><code>&lt;div class="container"&gt;
  
      &lt;form #loginForm="ngForm" (ngSubmit)="login()" class="form-signin"&gt;
          &lt;h2 class="form-signin-heading"&gt;Please sign in&lt;/h2&gt;
          &lt;label for="email" class="sr-only"&gt;Email&lt;/label&gt;
          &lt;input type="email"  ngControl="email" [(ngModel)]="_user.email" #email id="email"  class="form-control" placeholder="email" required autofocus&gt;
          &lt;label for="password" class="sr-only"&gt;Password&lt;/label&gt;
          &lt;input type="password" ngControl="password" [(ngModel)]="_user.password" #password id="password"  class="form-control" placeholder="Password" required&gt;
          &lt;div class="checkbox"&gt;
              &lt;label&gt;
                  &lt;input type="checkbox" value="remember-me"&gt; Remember me
              &lt;/label&gt;
          &lt;/div&gt;
          &lt;button class="btn btn-lg btn-primary btn-block" type="submit"&gt;Sign in&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and this is my controller</p>
  
  <pre><code>@RequestMapping(value = "/login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
      public ResponseEntity&lt;User_khalil&gt; login(User_khalil user) {
          System.out.println("------- " + user.getEmail() + user.getPassword());
  
          User_khalil u = userRepository_khalil.findOneByEmailAndPassword(user.getEmail(), user.getPassword());
          if (u != null) {
              return new ResponseEntity&lt;User_khalil&gt;(user, HttpStatus.OK);
          }
          return new ResponseEntity&lt;User_khalil&gt;(user, HttpStatus.OK);
      }
  </code></pre>