Java Dropzone-从服务器获取响应

Java Dropzone-从服务器获取响应,java,ajax,struts2,response,dropzone.js,Java,Ajax,Struts2,Response,Dropzone.js,我正在尝试创建一个带有拖放区的页面。文件上传到服务器上,读取成功后必须返回信息消息 一切正常,而不是返回消息,我不能触发dropzone事件的任何事件 我的配置是: 雄猫7 爪哇8 支柱2 Dropzone.js 这是我的jsp代码 Dropzone.autoDiscover = false; $(document).ready(function() { $("#importIGHEdit").dropzone({ paramName: "fileTr

我正在尝试创建一个带有拖放区的页面。文件上传到服务器上,读取成功后必须返回信息消息

一切正常,而不是返回消息,我不能触发dropzone事件的任何事件

我的配置是:

  • 雄猫7
  • 爪哇8
  • 支柱2
  • Dropzone.js
这是我的jsp代码

Dropzone.autoDiscover = false;

$(document).ready(function() {

    $("#importIGHEdit").dropzone({
              paramName: "fileTransfert", // The name that will be used to transfer the file
              url: "importIGHAjax.action",
              maxFiles: 1,
              createImageThumbnails: true,// Max numbre of files
              acceptedFiles: "text/xml",
              addRemoveLinks: true,
              autoProcessQueue: false,
              init: function() {
                    var myDropzone = this;
                    var submitButton = document.getElementById("downloadButton");

                    // First change the button to actually tell Dropzone to process the queue.
                    submitButton.addEventListener("click", function(e) {
                      // Make sure that the form isn't actually being sent.
                      e.preventDefault();
                      e.stopPropagation();
                      myDropzone.processQueue();
                      uploadFileIGH();
                    });

                    this.on("addedfile", function(file) { alert("Added file."); });
                    this.on("error", function(file, errorMessage) { console.log(errorMessage); });
                    this.on("processing", function(file) { alert("processing"); });
                    this.on("uploadprogress", function(file) { alert("uploadprogress"); });
                    this.on("sending", function(file) { alert("sending."); });
                    this.on("success", function(file, response) { console.log(response); });
                    this.on("complete   ", function(file) { alert("complete "); });
                    this.on("canceled", function(file) { alert("canceled"); });
                    this.on("successmultiple", function(file) { alert("successmultiple"); });
              },
              success : function(data) {
                  console.log("success");
              },
              accept: function(file, done) {
                  console.log(file.name);
                  done();
              }
            });
});


您可以使用
success

$("div#js-dropzone").dropzone({
    url: "/api/mmm/orders/fileupload",
    method: 'POST',
    success: function (response) {
        console.log(response.xhr.response);
    }
});

Json响应应该在客户端处理。返回时,请确保其格式为应用程序接受的格式。我如何才能做到这一点?我不是用“success”或this.on(“success”、…)部分来做吗?如果
this.on(“success”、…)
part,你在做什么?我想验证文件,然后显示成功消息。这是另一个问题。
public String saveFileAjax() throws Exception{

    this.setAjxReturn(new HashMap<String, Object>());

    this.checkMandatoryFields();

    if(this.article.existsIndex(databaseName)){
        dropIndex();
    }

    importDataIGH();

    callProc();

    if(!this.article.existsIndex(databaseName)){
        createIndex();
    }

    return SUCCESS;
}
<action name="importIGHAjax" class="patinfo.gestionprojet.admin.ImportIGHEditAction" method="saveFileAjax">
  <result type="json" >
    <param name="root">ajxReturn</param>
  </result>
  <result name="success" type="json" >
    <param name="root">ajxReturn</param>
    <param name="statusCode">202</param>
  </result>
</action>
Request URL:http://localhost:8080/SAMinfo-tomcat/importIGHAjax.action
Referrer Policy:no-referrer-when-downgrade
Request Headers
Provisional headers are shown
Accept:application/json
Cache-Control:no-cache
Content-Type:multipart/form-data; boundary=----        WebKitFormBoundaryOYcna7y1OO7AhWHA
Origin:http://localhost:8080
Referer:http://localhost:8080/SAMinfo-tomcat/importIGHEdit.action
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payload
------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="cod_hack"

™
------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="id"


------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="action"

patinfo.gestionprojet.admin.ImportIGHEditAction@1aa6564d
------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="total"


------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="noCategorieArticle"

1
------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="codeCategorieTVA"

A
------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="noMonnaie"

1
------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="noCompte"

3400
------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="noCompte_widget"

3400
------WebKitFormBoundaryOYcna7y1OO7AhWHA
Content-Disposition: form-data; name="fileTransfert"; filename="BELIMO-1330-    2018-01-fr.xml"
Content-Type: text/xml


------WebKitFormBoundaryOYcna7y1OO7AhWHA--
$("div#js-dropzone").dropzone({
    url: "/api/mmm/orders/fileupload",
    method: 'POST',
    success: function (response) {
        console.log(response.xhr.response);
    }
});