简体   繁体   English

访问控制允许来源

[英]Access-Control-Allow-Origin

Hi I'm developing a web application using a REST web service as server side. 嗨,我正在使用REST Web服务作为服务器端开发Web应用程序。 When I make a call to rest web service from my client side it gives me the following error. 当我从客户端调用Rest Web Service时,出现以下错误。 Servie is running uder http://localhost:8010/service and client is running under http://localhost:8020/client . Servie正在运行uder http://localhost:8010/service ,客户端正在http://localhost:8020/client下运行。 I have deployed this in jetty. 我已经在码头部署了它。

XMLHttpRequest cannot load http://localhost:8010/Service/rest/employee/basicupdate. Origin http://localhost:8020 is not allowed by Access-Control-Allow-Origin.

Below I have included my rest method 下面我包括了我的休息方法

@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.

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