在我的.java 文件中,
每当文件上传并通过ajax提交表单时, upload.parseRequest(request)会正确返回所有字段,
但是每当提交一个没有文件的表单时, upload.parseRequest(request)返回空列表。
有人可以建议我任何解决方法吗?
if (!isMultipart) {
System.out.println("Inside isMultipart ------------------------->" + imageName);
}
DiskFileItemFactory factory = new DiskFileItemFactory();
// Location to save data that is larger than maxMemSize.
factory.setRepository(new File(imagesavingLocation));
FileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding(request.getCharacterEncoding());
List items = null;
items = upload.parseRequest(request);
Iterator iterator = items.iterator ();
我的js文件如下所示
var form = $('#merchantSignupForm')[0];
var fd = new FormData(form);
fd.append('firmname', $("#firmname").val());
fd.append('firmtype', $("#firmtype").val());
fd.append('pancard', $("#pancardnumber").val());
fd.append('vatnumber', $("#vatnumber").val());
fd.append('filevatnumber',$("input[name='filevatnumber']:checked").val());
fd.append('contactnumber', $("#contactnumber").val());
$.ajax({
type: 'POST',
async: false,
enctype: 'multipart/form-data',
url: urlCS+"?actionname=CustomerSupportAjaxHandler.setMerchantDetail&firmname="+$("#firmname").val(),
data: fd,
cache: false,
processData: false,
contentType: false,
success: function(data){
if(typeof data === "object" && data.status == 'success')
{
$("#merchantMsg").html("<span class='success_FieldText'>Merchant Sign up sucessfully</span>");
$('.realperson-text').click();
$(window).scrollTop($('#merchantMsg').offset().top);
$("#merchantSignupForm").get(0).reset();
}
else
{
$('.realperson-text').click();
$('#captcha').val('Type the word*');
$(window).scrollTop($('#merchantMsg').offset().top);
$("#merchantMsg").html("<span class='errMsg'> Error occured Please Try again ! </span>");
}
},
error: function()
{
$('.realperson-text').click();
$('#captcha').val('Type the word*');
$(window).scrollTop($('#merchantMsg').offset().top);
$("#merchantMsg").html("<span class='errMsg'> Error occured Please Try again !</span>");
}
});