Learn the file upload download, for the image upload to prepare, feel a century has not played upload download, edge-tapping code side record, please each road great God advice:
Reference: http://blog.csdn.net/wjycgl/article/details/55509480
1:jsp page from form: Here are two mandatory conditions. Must be a post-mode submission. 2: Must have enctype attribute, enctype= "Multipart/form-data"
Introduction of JAR packages in 2:maven Pom.xml
<!--file Upload--
- <dependency>
- <groupid< span class= "tag" >>commons-fileupload</groupid >
- < artifactid>commons-fileupload</ artifactid>
- <version>1.3.2 </version>
- </dependency>
3: Define the Commonsmultipartresolver file parser under Spring's servlet View parser, which is the time to run the project if no fileuload-related jar package is added.
<bean id= "Multipartresolver" class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver" >
<!--Set the default encoding--
<property name= "defaultencoding" value= "UTF-8"/>
<!--upload file maximum size 5m-->
<property name= "maxuploadsize" value= "5242440"/>
<!--the maximum size (threshold) allowed for file uploads, below this value, only in memory, exceeding this threshold, generating temporary files on the hard disk--
<property name= "Maxinmemorysize" value= "4096"/>
<!--set temporary file save path--
<property name= "Uploadtempdir" value= "Fileupload/temp"/>
</bean>
4: Controller class, request processing method parameters must have "Multipartfile file" or "Commonsmultipartfile file", and annotated @requestparam
5://Get file name
String fileName = File.getoriginalfilename ();
Get file type
String FileType = File.getcontenttype ();
Copy to specified location
Return "Success";
It's easier to write than to judge anything, so it can be achieved.
SPRINGMVC, Spring, MyBatis file upload