配置文件中 byte
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" > <property name="maxUploadSize" value="10240000"></property> <property name="defaultEncoding" value="UTF-8"></property>
</bean> |
网页
<form action="c" method="post" enctype="multipart/form-data"> 照片<input type="file" name="file"> <input type="submit"> </form> |
需要导入的jar包(下边是链接)
链接:https://pan.baidu.com/s/1dYJqrt7DmEVfXIeMA2u42w
提取码:lyfn
![](https://img-blog.csdnimg.cn/e79ae9d28239435d987cb7e6e3033e18.png)
Controller
//获取文件名 String oldFileName=attach.getOriginalFilename(); String path=request.getSession().getServletContext(). getRealPath("img"); System.out.println(path+"path"); System.out.println(oldFileName); File f=new File(path,oldFileName);
attach.transferTo(f); |
![](https://img-blog.csdnimg.cn/eca382e9a53047969edfe50d61e2aea4.png)