I am running into strange problem while trying to upload multiple files using ajax. why we are using Ajax to upload multiple file ? Because user wants to review all the files which he/she is trying to upload to server. what mean by review is, user should be allowed to delete file before uploading to server.
What i tried so far?
JSP
<form id="form1" method="post" action="uploadMultipleFiles" enctype="multipart/form-data">
<!-- File input -->
<input name="file" id="files" type="file" multiple="multiple"/><br/>
<button value="Submit" onclick="uploadFiles()" >Upload</button><i>upload</i>
</form>
JS
function uploadFiles(){
var files = $("#files").prop("files");
var oMyForm = new FormData();
oMyForm.append("file", files[0]); //currently trying with only one file
$.ajax({
url: 'uploadMultipleFiles',
data: oMyForm,
// dataType: 'text',
processData: false,
contentType: false,
type: 'POST',
success: function(data){
console.log(data)
}
});
}
Spring Controller (Version 3.0.0 release)
@RequestMapping(value = "/uploadMultipleFiles", method = RequestMethod.POST)
public @ResponseBody String uploadMultipleFilesHandler(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
System.out.println(multipartRequest);
}
I have not included entire code of controller but i believe it should be sufficient for any pointer which you can provide.
Spring bean configuartion
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="900000" />
</bean>
Exception
java.lang.ClassCastException: com.ibm.ws.webcontainer31.srt.SRTServletRequest31 cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
Kindly help me figure out what i could do to resolve this exception and please note same code is working file in tomcat however WebSphere Liberty profile seems to have some issue.