[英]Access-Control-Allow-Origin
嗨,我正在使用REST Web服務作為服務器端開發Web應用程序。 當我從客戶端調用Rest Web Service時,出現以下錯誤。 Servie正在運行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;
}
<web-app>
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedMethods</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.