Spring文件上传

1.拷jar

2.配置spring核心文件

 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
     <property name="maxUploadSize" value="104857600" />
     <property name="maxInMemorySize" value="4096" />
     <property name="defaultEncoding" value="UTF-8"></property>
</bean>

3.写控制器

 @RequestMapping("Upload")
	    public String  springUpload(MultipartFile file,Model model) throws IllegalStateException, IOException{
		 String path = "e:\\"+file.getOriginalFilename();//新文件路径+名字
		 file.transferTo(new File(path));
		 return "MyJsp";
	 }

4.form表单

<form name="Form2" action="Upload" method="post"  enctype="multipart/form-data">
	<input type="file" name="file">
	<input type="submit" value="上传"/>
</form>

  

posted @ 2019-04-16 11:49  致颜文磊  阅读(235)  评论(0编辑  收藏  举报