1. 程式人生 > >springmvc 文件上傳

springmvc 文件上傳

gin tor com ipa print inpu lte ioe val

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 文件上傳