Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 访问控制允许在Maven build web.xml中设置源标题_Java_Jquery_Rest_Maven_Cors - Fatal编程技术网

Java 访问控制允许在Maven build web.xml中设置源标题

Java 访问控制允许在Maven build web.xml中设置源标题,java,jquery,rest,maven,cors,Java,Jquery,Rest,Maven,Cors,当我使用jQuery访问其余部分时,我得到以下错误 XMLHttpRequest cannot load http://localhost:8185/Profile-iris/Profile.svc/GB0010001/enqEnqUserProfiles()?alt=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not

当我使用jQuery访问其余部分时,我得到以下错误

XMLHttpRequest cannot load http://localhost:8185/Profile-iris/Profile.svc/GB0010001/enqEnqUserProfiles()?alt=json.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 401.
我知道我需要在服务器上设置访问控制允许原点

下面是服务器端的“web.xml”

<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>GET,POST,DELETE,PUT,HEAD</param-value>
    </init-param>
    <init-param>
        <param-name>allowedHeaders</param-name>
        <param-value>origin,content-type,accept,authorization,maxdataserviceversion</param-value>
    </init-param>
</filter>
....
....
<filter-mapping>
    <filter-name>cross-origin</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
jQuery客户端

    <script>
        $(document).ready(function() {
            $.ajax({
                url: "http://localhost:8185/Profile-iris/Profile.svc/GB0010001/enqEnqUserProfiles()?alt=json",
                type: "GET",
                dataType : "json",

                success: function(data){
                    console.log(data);
                },
                error: function(error){
                    console.log(error);
                }
            })
        });
    </script>

$(文档).ready(函数(){
$.ajax({
url:“http://localhost:8185/Profile-iris/Profile.svc/GB0010001/enqenquersprofiles()?alt=json“,
键入:“获取”,
数据类型:“json”,
成功:功能(数据){
控制台日志(数据);
},
错误:函数(错误){
console.log(错误);
}
})
});

据我所知,上述设置看起来是正确的。但无论如何,我得到了同样的错误。有人能帮帮我吗。

当你在当地环境中工作时,有时会发生这种情况。如果是这样的话,您可以只使用Google Chrome扩展:


在本地环境中打开并忘记此错误消息。

谢谢。我已安装并启用,但现在我得到
XMLHttpRequest无法加载http://localhost:8185/Profile-iris/Profile.svc/GB0010001/enqenquersprofiles()?alt=json。飞行前的响应具有无效的HTTP状态代码401
任何建议??HTTP 401->未经授权的请求我认为这两个问题是不同的。401可能是另一个问题。
    <script>
        $(document).ready(function() {
            $.ajax({
                url: "http://localhost:8185/Profile-iris/Profile.svc/GB0010001/enqEnqUserProfiles()?alt=json",
                type: "GET",
                dataType : "json",

                success: function(data){
                    console.log(data);
                },
                error: function(error){
                    console.log(error);
                }
            })
        });
    </script>