I want to cast httpServletRequest to multipartHttpServletRequest. When I try this, a ClassCastException occurs.
MultipartHttpServletRequest request = (MultipartHttpServletRequest)req;
This error occurred only for AJAX call, for form submit it doesn’t happen.
I’ve done all necessary steps as follows:
- Use
commons-fileupload.jar - Set
enctype="multipart/form-data" - Define
multiparResolverbean in spring context.
Please help.
Yes, through Ajax you cannot upload file content, so as request not having any file content spring cannot prepare MultipartHttpServletRequest, which causes
ClassCastException. Then you have to use technique of usingiframein html to upload file while givingajaxstyle upload.