Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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 将文件从GWT上载到另一个域,响应始终为空_Java_Gwt - Fatal编程技术网

Java 将文件从GWT上载到另一个域,响应始终为空

Java 将文件从GWT上载到另一个域,响应始终为空,java,gwt,Java,Gwt,我正在将一个文件从GWT上载到另一个域 文件上传良好,但我从服务器发送的响应在客户端总是达到“null” response.setContentType("text/html"); response.setHeader("Access-Control-Allow-Origin", "*"); response.getW

我正在将一个文件从GWT上载到另一个域

文件上传良好,但我从服务器发送的响应在客户端总是达到“null”

                    response.setContentType("text/html");
                    response.setHeader("Access-Control-Allow-Origin", "*");
                    response.getWriter().print("TEST");
仅当我将文件上载到其他域时,响应才为空。。。(在同一个域上,一切正常)

我在GWT文档中也看到了这一点

 Tip:
 The result html can be null as a result of submitting a form to a different domain.


当我将文件上载到其他域时,是否有任何方法可以在客户端收到回复?有两种可能的答案:

  • 使用生成器
  • 希望能有帮助

        JsonpRequestBuilder requestBuilder = new JsonpRequestBuilder();
        requestBuilder.requestObject(url, new AsyncCallback<FbUser>() {
        @Override
        public void onFailure(Throwable ex) {
            throw SOMETHING_EXCEPTION(ex);
        }
    
        @Override
        public void onSuccess(ResponseModel resp) {
            if (resp.isError()) {
                // on response error on something
                log.error(resp.getError().getMessage())
                log.error(resp.getError().getCode())
            }
            
            log.info(resp.getAnyData())
        }
    
    public uploadFile() {
        HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();
        HttpPost httpPost = new HttpPost(url);
    
        FileBody bin = new FileBody(new File(UPLOADED_FILE));
        long size = bin.getContentLength();
    
        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("PART", bin);
        String content = "-";
        try {
             httpPost.setEntity(reqEntity);
                HttpResponse response = httpClient.execute(httpPost, localContext);
                HttpEntity ent = response.getEntity();
                InputStream st = ent.getContent();
                StringWriter writer = new StringWriter();
                IOUtils.copy(st, writer);
                content = writer.toString();                
    
        } catch (IOException e) {                   
            return "false";
        }
        return content;
    }