Uploading multiple files using JSP, Spring with Single Browse button and Single request

*爱你&永不变心* 提交于 2019-12-25 07:58:30

问题


When I attach two or more files from my front end, in log.debug used in the POST method I get only 01 file name and file list size also shows 01. How can I get all my attached files in my POST method ???

I have my Model class as:

//Model
public class MailSenderBean {
    private List<MultipartFile> files;
}

JSP View as below with enctype="multipart/form-data" :

<input name="files" id="filesToUpload" class="button" type="file" multiple/>

Controller as:

//Controller
@RequestMapping(value = "/sendFiles", method = RequestMethod.POST)
        public ModelAndView sendFiles(@ModelAttribute("mailSenderBean") MailSenderBean mailBean, BindingResult result,HttpServletRequest request) {
            User user = AuthManager.getUser( request );

            List<MultipartFile> files = mailBean.getFiles();
            log.debug(" Size ---->>>> "+files.size());

             for (MultipartFile multipartFile : files) {
                  log.debug("Name ===== >>> "+multipartFile.getOriginalFilename() );
             }
    }

来源:https://stackoverflow.com/questions/39569107/uploading-multiple-files-using-jsp-spring-with-single-browse-button-and-single

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!