对servlet的multipart ajax请求 - request.getParameter()返回null

时间:2016-10-18 05:55:35

标签: html servlets request multipartform-data ajaxform

我通过Ajax提交请求,但每当我发送多部分请求请求时,.getParameter总是返回null。没有多部分请求其工作

JS代码

$scope.saveProduct = function () {
    var urlForCreateProduct = getUrl("create_product");
    var formData = new FormData();
    formData.append('file', $('#product_image')[0].files[0]);
    formData.append('product_title',$scope.Product.product_title);
    formData.append('product_desc',$scope.Product.product_desc);
    formData.append('product_details',$scope.Product.product_details);
    formData.append('product_price',$scope.Product.product_price);
    formData.append('product_category',$scope.Product.product_category);
    formData.append('product_id',getUniqueID() + "");

    $.ajax({
        url: urlForCreateProduct,
        type: "POST",
        processData: false,
        contentType: false,
        data: formData,
        cache: false,
        success: function(response){
            if(response.status && response.status == "success"){
                toastr.success('Product Created!');
                $('#addProductModel').modal('hide');
            } else {
                /* error */
                toastr.error(response.message);
            }
        },
        error: function(error){
            /* error */
            toastr.error(error.message);
        }
    });
};

0 个答案:

没有答案