File upload working under Jetty but not under Tomcat

后端 未结 2 674
小蘑菇
小蘑菇 2021-01-06 07:49

I have a web application with spring in which I do some file upload. Under eclipse, using Jetty (the maven plugin) it works perfectly. But when I deploy the application unde

2条回答
  •  粉色の甜心
    2021-01-06 08:37

    Thanks to @Bart I was able to find the following simple solution :

    In the intercepting method, use @ModelAttribute instead of @RequestParam :

    @RequestMapping(value = IMPORT_PAGE, method = RequestMethod.POST)
    public String recieveFile(@RequestParam("importType") String importType,
            @ModelAttribute("file") UploadedFile uploadedFile, final HttpSession session)
    {
        MultipartFile multipartFile = uploadedFile.getFile();
    

    Where UploadedFile is the following class :

    public class UploadedFile
    {
        private String type;
    
        private MultipartFile file;
    
        public String getType()
        {
            return type;
        }
    
        public void setType(String type)
        {
            this.type = type;
        }
    
        public void setFile(MultipartFile file)
        {
            this.file = file;
        }
    
        public MultipartFile getFile()
        {
            return file;
        }
    }
    

    And it's working !!

    Thanks everyone for your help.

提交回复
热议问题