Angular2发布但仍无法通过动作获取struts中的值

时间:2018-02-23 03:30:43

标签: angular

这是我的服务。:

private urlConfigData = "/GATS-QTI-NG/generationconfigfile.action";

generateConfigfile(data): Observable<any>{

let options = new RequestOptions({ headers: this.headers });

return this.http.post(this.urlConfigData, "hello", options)

                .map((response: Response) => console.log(response))
                .catch (this.handleError);
}

component.ts:

const req = 
     this.integrationTestService.generateConfigfile(this.configDataGroup)
    .subscribe(
    res => {
        console.log(res);
      },
      err => {
        console.log("Error occurred");
      })

Java端的结果为null。我也将网址更改为此但没有效果:

private urlConfigData = "/GATS-QTI-NG/generationconfigfile.action?data=";

1 个答案:

答案 0 :(得分:0)

试试这个它对我有用,

我的组件方法,

import {Http, Headers, Response, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs/Rx';

var response = this.service.post('your...url/hello', null);
    response.subscribe((res) => {
    var response = res.json();
});

Service Post方法,

post(url: string, data : any): Observable<any> {
      let headers = new Headers();
      headers.append('Content-Type', 'application/json');

      let options = new RequestOptions({ headers: headers});
      return this.http.post(url, data,options);

}