Could not parse multipart servlet request, nested exception is org.apache.commons.fileupload.FileUploadException
As @ChristianMaioliM requested in comment, added more details about The problem in your code is the BindingResult parameters not following the model object.
The Errors or BindingResult parameters have to follow the model object that is being bound immediately as the method signature might have more than one model object and Spring will create a separate BindingResult instance for each of them so the following sample won’t work
Refer docs Invalid ordering of BindingResult and @ModelAttribute
To resolve, change your controller method handler signature to follow parameter ordering between BindingResult & model object like:
From:
@RequestMapping(value="/uploadForm",method = RequestMethod.POST)
public @ResponseBody String uploadForm1(@ModelAttribute("admin") BillingAndRecon billingandrecon,@RequestParam String id,BindingResult result,Principal principal,@RequestParam MultipartFile file,HttpSession session) throws ServiceException, DaoException, IllegalStateException, IOException {
To:
@RequestMapping(value="/uploadForm",method = RequestMethod.POST)
public String uploadForm1(
@ModelAttribute("admin") BillingAndRecon billingandrecon,
BindingResult result,
Principal principal,
HttpSession session) throws ServiceException, DaoException, IllegalStateException, IOException {
//do file save here
return "some-view-name";
}
and in BillingAndRecon class add mulitpart/binding fields like:
public class BillingAndRecon {
private MultipartFile file;
private String id;
no-arg constructor;
getters;
setters;
}
Note: BindingResult argument should be after immediate of @ModelAttrubiute/@RequestBody
and jsp form:
<form:form action="${pageContext.request.contextPath}/uploadForm"
method="post"
enctype="multipart/form-data"
modelAttribute="admin">
<input type="file" name="file" />
<form:input path="id" />
</form:form>
and don't forget to add for binding instance in GET handler like:
@RequestMapping(value="/uploadForm",method = RequestMethod.GET)
public String uploadFormView(Model model){
model.addAttribute("admin", new BillingAndRecon());
return "your-upload-view-name";
}