您好我正在開發一個使用REST Web服務作爲服務器端的Web應用程序。當我從客戶端撥打電話以休息Web服務時,它會給我以下錯誤。服務正在運行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;
}
? –