2015-06-14 58 views
0

我想为在谷歌应用引擎上运行的GWT应用程序实现文件上传。我用GWTUpload,但收到以下错误,如果我尝试上传文件:GWT Upload on Google Appengine - 跨站点保护

<stdout>: 2015-06-14 17:50:35 ERROR UploadServlet:70 - checkCORS error Origin: http://myApp.appspot.com does not match:^$ 

我看着UploadServlet,实际上没有对原产againg“^ $”的支票。我不太相信这个正则表达式匹配“^”似乎是字符串的开始和“$”的结尾。但似乎只匹配一个空字符串?

private boolean checkCORS(HttpServletRequest request, HttpServletResponse response) { 
    String origin = request.getHeader("Origin"); 
    if (origin != null && origin.matches(corsDomainsRegex)) { 
     // Maybe the user has used this domain before and has a session-cookie, we delete it 
     // Cookie c = new Cookie("JSESSIONID", ""); 
     // c.setMaxAge(0); 
     // response.addCookie(c); 
     // All doXX methods should set these header 
     response.addHeader("Access-Control-Allow-Origin", origin); 
     response.addHeader("Access-Control-Allow-Credentials", "true"); 
     return true; 
    } else if (origin != null) { 
     logger.error("checkCORS error Origin: " + origin + " does not match:" + corsDomainsRegex); 
    } 
    return false; 
    } 

我不能设置“corsDomainsRegex”或重写checkCORS()方法,因为它们都是私有的。这里的实际问题是什么?我该如何解决这个问题?

回答

1

这是一个硬连线检查,以防止人们通过其他域名上传文件。如果你不需要这个,你可以通过添加以下内容到你的web.xml(或者你想检查的任何域)来更改corsDomainsRegex。

<context-param> 
    <!-- match all domains --> 
    <param-name>corsDomainsRegex</param-name> 
    <param-value>.*</param-value> 
</context-param>