File Upload to Server Directory Using Spring MVC

后端 未结 2 1548
感动是毒
感动是毒 2020-12-19 13:37

I am trying to upload a file to the server directory from client machine. I used the following codes :

FileUpload.jsp



        
相关标签:
2条回答
  • 2020-12-19 14:12
    @RequestMapping("/upload.action")
    public String upload(@RequestParam("fileData") MultipartFile file,
            HttpServletResponse response,Model model)
    {
        //Controller logic...
    }
    

    you should have the same name in the parameter for your request handler method ,whatever you given in the FileUpload Pojo for multipartFile ("fileData") it should be in the parameter

    Thanks,

    0 讨论(0)
  • 2020-12-19 14:24

    Try adding the MultipartFile as a parameter in your requesthandler.

    @RequestMapping("/upload.action")
    public String upload(@RequestParam(value = "file") MultipartFile file,
            HttpServletResponse response,Model model)
    {
        //Controller logic...
    }
    

    This will require you to register a new bean in your dispatcher's configuration.

    <bean id="multipartResolver"
       class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="5000000"/>
    </bean>
    
    0 讨论(0)
提交回复
热议问题