Access-Control-Allow-Origin突然不起作用

时间:2014-10-12 22:26:29

标签: javascript jquery tomcat

我们有一个只在ipad上运行的移动应用程序。在应用程序中,用户提交表单,应用程序将使用js / jquery在服务器上调用restful服务。服务器是tomcat 6,Web应用程序使用spring + hibernate框架。在开发服务器上我们遇到了cors问题,我在web.xml INSIDE我的应用程序中添加了相应的过滤器,当然还有jar文件。它在开发,qa和实时服务器上运行良好,应用程序可以与服务器协调通信。但是今天晚些时候我刚收到客户的错误报告,该应用无法将数据上传到服务器,除非重新安装应用程序,以此方式保存在应用程序中的所有数据都将消失。我使用javascipt和app内部测试。奇怪的是我总是使用脚本得到异常:

XMLHttpRequest cannot load https://mobilesso.vw.com.cn/ssso/scc/registerSCCF. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

始终可以通过应用程序将数据上传到服务器。我想知道为什么它现在正在发生。移动应用程序和网络应用程序可以在一周内完成,以及为什么它从现在开始停止。为什么应用程序内部没有问题,但js确实存在问题。任何建议都会有所帮助。

有客户端测试代码:

<script type="text/javascript" id="address-candidate-template">
var request = null;

function getMessage()
{
    alert("Begin the test");
    createRequest();
    var url = "my url";
    request.onreadystatechange = handleResponse;
    request.open("GET", url, true);
    request.send(null);
}

function createRequest() {
    try {
        request = new XMLHttpRequest();
    } catch (trymicrosoft) {
        try {
            request = new ActiveXObject("MsXML2.XMLHTTP");
        } catch (othermicrosoft) {
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (failed) {
                request = null;
            }
        }
    }

    if (request == null)
        alert("Error creating request object!");
}

function handleResponse() {
    alert(request.readyState + " " + request.status);
    if (request.readyState==4 && request.status==200)
    {
        var xmlDocument=request.responseXML;
        var fnames = xmlDocument.getElementsByTagName("statusCode");
        var v1 = fnames[0].childNodes[0].nodeValue;
        fnames = xmlDocument.getElementsByTagName("statusText");
        var v2 = fnames[0].childNodes[0].nodeValue;
        alert("Result:\nstatusCode: " + v1 + "\nstatusText: " + v2);  
    }

}
</script>
<div>
    <p>test the connectivity</p><input type="button" value="Get Result"   onclick="getMessage()"/>

我使用了以下maven依赖:

 <dependency>
    <groupId>com.thetransactioncompany</groupId>
    <artifactId>cors-filter</artifactId>
    <version>1.9.3</version>
</dependency>

并设置WEB-INF / web.xml:

 <!-- CORS Filter -->
    <filter>
        <filter-name>CORS</filter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
    </filter>
    <filter-mapping>
            <filter-name>CORS</filter-name>
            <url-pattern>/*</url-pattern>
    </filter-mapping>

0 个答案:

没有答案
相关问题