<!-- 配置上传文件MultipartResolver-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--配置上传文件的编码方式 -->
<property name="defaultEncoding" value="UTF-8"/>
<!--配置上传文件最大值 -->
<property name="maxUploadSize" value="102400000"/>
</bean>
------------------------------------------------------------------jsp--------------------------------------------------------------------------<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>
------------------------------------------------------------------PersonHandler.java----------------------------------------------------------------------@RequestMapping("/testFileUpload")
public String testFileUpload(@RequestParam("desc") String desc, @RequestParam("file") MultipartFile file) throws IOException {
System.out.println(desc);
System.out.println(file.getName() + "..." + file.getOriginalFilename());
System.out.println(file.getInputStream());
return "secces";
}
版权声明:本文为博主原创文章,未经博主允许不得转载。