简体   繁体   English

Angular POST RESTful API 到 Ejb 导致 404 not found 错误

[英]Angular POST RESTful API to Ejb resulting in 404 not found error

I was having some problem when trying to send RESTful API from Angular to EJB.我在尝试将 RESTful API 从 Angular 发送到 EJB 时遇到了一些问题。 Here is my component.ts:这是我的component.ts:

this.opUserAdminWinService.retrievePegRoleList().subscribe(resf => {
        console.log(resf);
});

And my service.ts:还有我的 service.ts:

serviceAPI = SERVER_API_URL;
mainAPI = '/api/securityactivity/securityactivity';
retrievePegRoleList() {
    const url: string = this.serviceAPI + this.mainAPI + '/RetrievePegRoleList';
    return this.http.post(url, this.httpOptions);
}

In my Controller.java:在我的 Controller.java 中:

@PostMapping("/RetrievePegRoleList")
public Vector RetrievePegRoleList()
    throws JaMClientRemoteException, JaMException {
    return getSecurityActivity().RetrievePegRoleList();
}

In my EjbBean class:在我的 EjbBean class 中:

public Vector RetrievePegRoleList() throws JaMClientRemoteException, JaMException;

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Vector RetrievePegRoleList() throws JaMClientRemoteException, JaMException
{
    Vector pegRoleList;
    try {
        String dataSource = JaM.getProperties().ORD_DATA_SOURCE;
        RetrievePegRoleListTask retrievePegRoleListTask = new RetrievePegRoleListTask(dataSource);
        retrievePegRoleListTask.execute();
        pegRoleList = retrievePegRoleListTask.getResult();
    } catch (Exception e) {
        throw new JaMClientRemoteException(this.ERR_EXCEPTION_JAM, e.toString());
    }
    return pegRoleList;
}

However, I am getting this error message:但是,我收到此错误消息:

在此处输入图像描述

Any ideas why is it so?任何想法为什么会这样? Thanks!谢谢!

try this in angular.在 angular 中试试这个。

export const httpOptions = {
    headers: new HttpHeaders({
        'Content-Type': 'application/json'
    })
};
this.http.post(your-url,your-data, httpOptions);

I always send post like this in angular.我总是在 angular 中发送这样的帖子。 If it doesn't work.如果它不起作用。 You should examine,is there an interceptor in Server.您应该检查一下,Server 中是否有拦截器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM