getParameter返回NULL并且无法识别getPart,请求不包含多部分/表单数据或多部分/混合流

时间:2019-04-09 04:08:22

标签: javascript java ajax servlets

我有两个问题。 我的Servlet最初在一个HTML页面上工作,该页面允许用户输入名称并上传2个文件。 但是,在我的一位同事添加了一些JS代码之后,整个页面似乎都破了

问题1:尽管输入值,总工程师和驳船主任仍返回null。

问题2:signatureFilePartCE引发错误请求,其中不包含multipart / form-data。该行之后的S.O.P也不会出现

我尝试将 mov edx, 1 xor rax, rax div rdi ret 添加到我的servlet中。 在前端,我尝试调整JS代码以添加@MultipartConfigenctype: 'multipart/form-data',但无济于事。

Servlet

contentType: false

JS

String chiefEngineerName = request.getParameter("chiefName");
String bargeOfficerName = request.getParameter("bargeName");

if (chiefEngineerName != null) {
  boolean check = ExternalUserDAO.checkIfExternalUserRecordExist(jobRefNo, chiefEngineerName);
  System.out.println("Check is: " + check);
  if (!check) {
    chiefEngineer = new ExternalUser(jobRefNo, chiefEngineerName, null, null, "Chief Engineer");
    ExternalUserDAO.insertExternalUser(chiefEngineer);
  }
}
System.out.println("Chief Engineer is: " + chiefEngineerName);
System.out.println("Barge Officer is: " + bargeOfficerName);
Part signatureFilePartForCE = null;

//Retrieving filePart using JS?
try {
  signatureFilePartForCE = request.getPart("chiefSign");
  System.out.println("Hello");
} catch(Exception e) {
  System.out.println(e.getMessage());
}

HTML

$("form").submit(function(e) {
  e.preventDefault();

  $.ajax({
    type: "POST",
    //url: domain + '/The_Sailors_Application/UploadExternalUserInfoServlet?referenceNumber' + referenceNo,
    url: domain + '/The_Sailors_Application/TestingServlet?referenceNumber' + referenceNo,
    //data: $(this).serialize(),
    enctype: 'multipart/form-data',
    //contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
    //contentType: false,
    success: function() {
      // callback code here
      $('#errorMessageBox').css("display", "block");
      displayErrorMessage("success", "The changes made to this form had been saved.");
      $(window).scrollTop(0);
      //window.location.href = "timelog.html?referenceNo=" + referenceNo;
    },
    error: function(error) {
      $('#errorMessageBox').css("display", "block");
      displayErrorMessage("danger", "The changes made to this form had failed to be saved. Please try again.");
      $(window).scrollTop(0);
    }

  })
});

0 个答案:

没有答案