获取null`request.parts`通过jQuery Ajax将文件发布到java servlet

时间:2017-05-17 10:08:05

标签: java jquery ajax servlets

这是我的js代码:

function sendMP3ViaAJAX(MP3File) {
    console.log(MP3File.name); //file is present, as I can get its name
      $.ajax({type: "POST",
        url: "saveMP3",
        enctype: 'multipart/form-data',
        processData: false,
        data: {'mp3File': MP3File},
        success: function (text)
        {
            response = text;
        },
        complete: function () {
             $("#retourAJAX").html("blah blah");
        }
    });
}

但如果我调试我的项目

 @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        Part part = request.getPart("MP3FILE"); //request.parts is null...

enter image description here

(常量CHAMP_FICHIER等于AJAX调用中定义的那个,即mp3File ...)你知道缺少什么吗?由于我已经在页面上动态加载了内容,因此我不希望发生默认的HTML POST提交行为...

0 个答案:

没有答案