Angular2の新機能です。 Angular2から簡単なJava REST呼び出しを呼び出そうとしています。私がデータを投稿しているとき、私はエラーを全く得ていませんが、私のjava postメソッドは呼び出されません。POSTメソッドがAngular2で機能しない
Angular2 POST-
let emplyee = JSON.stringify(this.object);
let url = 'http://localhost:8080/rest-app/rest/employeeService/insertEmployee';
console.log("Data: " + emplyee);
let headers = new Headers({'Content-Type': 'application/json'});
let options = new RequestOptions({headers: headers});
this.http.post(url, emplyee, options);
JavaのPOSTは、あなたが約束を使用したい場合は、同じように使用this-
this.http.post(url, emplyee, options)
.subscribe((response) => {
//handle response here
})
.catch(this.handleError);
のようにサブスクライブを追加する必要があり
@POST
@Path("/insertEmployee")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String insertEmployee(String employee) {
logger.debug("Employee: " + employee);
return "Hello";
}
あなたの回答は何ですか? this.http.post()の直後に応答を 'console.log'に' .subscribe(res => console.log(res)) 'を追加してください。 – Supamiu
応答のための@Supamiu thnx、この応答があります。**プリフライト要求への応答がアクセス制御チェックを通過しません:要求されたリソースに 'Access-Control-Allow-Origin'ヘッダーがありません。したがって、 'http:// localhost:3000'はアクセスが許可されていません。** – deen