您好我正在开发一个使用 REST Web 服务作为服务器端的 Web 应用程序。当我从客户端调用 rest web 服务时,它给了我以下错误。服务在 uder 下运行http://localhost:8010/service
,客户端在http://localhost:8020/client
. 我已经在码头部署了这个。
XMLHttpRequest cannot load http://localhost:8010/Service/rest/employee/basicupdate. Origin http://localhost:8020 is not allowed by Access-Control-Allow-Origin.
下面我已经包括了我的休息方法
@POST
@Path("/basicupdate")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Context
public String isValidLogin(@FormParam("employeeId") int employeeId, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName, @FormParam("gender") String gender, @FormParam("dob") String dob ) throws JsonGenerationException, JsonMappingException, IOException{
Response response = new Response();
String responseString = "";
try {
//Application logic
response.setCode(MessageCode.SUCCESS);
response.setMessage("Successfully Updated");
} catch (CustomException e) {
response.setCode(MessageCode.ERROR);
response.setMessage(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
response.setCode(MessageCode.ERROR);
response.setMessage(e.getMessage());
e.printStackTrace();
}finally{
responseString = mapper.writeValueAsString(response);
}
return responseString;
}