码迷,mamicode.com
首页 > 编程语言 > 详细

springmvc 文件上传

时间:2018-12-09 14:06:48      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:input   throw   print   return   tip   encoding   code   col   tin   

commons-fileupload-1.2.1.jar
commons-io-2.0.jar

    <!-- 配置 MultipartResolver -->
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="UTF-8"></property>
        <property name="maxUploadSize" value="1024000"></property>    
    </bean>    
    <form action="testFileUpload" method="POST" enctype="multipart/form-data">
        File: <input type="file" name="file"/>
        Desc: <input type="text" name="desc"/>
        <input type="submit" value="Submit"/>
    </form>
    @RequestMapping("/testFileUpload")
    public String testFileUpload(@RequestParam("desc") String desc, 
            @RequestParam("file") MultipartFile file) throws IOException{
        System.out.println("desc: " + desc);
        System.out.println("OriginalFilename: " + file.getOriginalFilename());
        System.out.println("InputStream: " + file.getInputStream());
        return "success";
    }

 

springmvc 文件上传

标签:input   throw   print   return   tip   encoding   code   col   tin   

原文地址:https://www.cnblogs.com/znsongshu/p/10090451.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!