I am sending one file to the tomcat server using jQuery FormData. The file is being received successfully on the server but any other value which I send with the file is not being received. For processing the file upload, I am using http://commons.apache.org/proper/commons-fileupload/ and http://commons.apache.org/io/. It is getting my file somehow. But when I write
request.getParameter("file")
in the servlet for the below code, it returns null. Even it doesn't show any parameter in the request object. I don't understand how it gets the file then. Can anyone help me to solve this?
$('#uploadCourseDetail').click(function() {
var form_data = new FormData();
if (!($('#courseDetails').prop('files')[0] == undefined)) {
var file_data = $('#courseDetails').prop('files')[0];
form_data.append('file', 'examdetail');
form_data.append('courseDetails', file_data);
}
$.ajax({
url: 'Exam_TimeTable_Scheduler_bySlots_Web_Project/FileUploadServlet',
type: 'POST',
contentType: false,
processData: false,
cache: false,
data: form_data,
success: function(data) {
alert("File Uploaded Successfully !");
}
});
});
I use firebug to track the requests. It shows that both the fields are being sent to the server. Below is the snapshot for the same: