<!--Spring MVC xml Middle configuration -->
<!-- defaultEncoding Default encoding ;maxUploadSize Limit the size -->
<!-- To configure MultipartResolver For file upload Use spring Of CommosMultipartResolver -->
<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="UTF-8"
p:maxUploadSize="100000000" >
</beans:bean>

2.HTML or JSP Add upload button to the page

<form action="fileUpload.do" method="post" enctype="multipart/form-data">
Select File :<input type="file" name="file">
<input type="submit" value=" Submit ">
</form>

3.Controller

public String addContentB(@RequestParam("textFile") MultipartFile textFile,HttpServletRequest request,Model model,Content news){
String path = request.getSession().getServletContext().getRealPath("upload");// Get path
String fileName = textFile.getOriginalFilename();// Get the name of the uploaded file
File targetFile = new File(path, fileName);
if(!targetFile.exists()){
targetFile.mkdirs();// Whether there is a directory , Create... If it doesn't exist
}
// preservation
try {
textFile.transferTo(targetFile); // Save the picture
} catch (Exception e) {
e.printStackTrace();
}
return "sssss";
}

API Address

https://docs.spring.io/spring/docs/2.0.0/javadoc-api/org/springframework/web/multipart/MultipartFile.html

Spring MVC MultipartFile More related articles to upload pictures

  1. MUI + Spring MVC Multi image upload

    Background code , Mainly SpringMVC Receive multiple file uploads , It's not for use MutilFiles The way , Mainly because MUI 5+ File upload is not supported Key It's the same name private String saveFile(Mu ...

  2. Spring MVC - MultipartFile File upload ( Single file and multi file upload )

    preparation : You need to build a spirngmvc Of maven project 1. Join in jar package <dependency> <groupId>commons-fileupload</gro ...

  3. Spring MVC Upload and download files

    A few days ago, a student of Jiangsu economy and trade left a message with me and asked me such a question :“ What technology is used to upload and download files on general web pages ? Is it a frame or a frame Java Medium IO flow ”. I replied that :“ Use Spring MVC Frameworks can do this , because Spri ...

  4. About how I use spring mvc Framework to do file upload problems encountered

    Thank you very much original text :https://blog.csdn.net/lingirl/article/details/1714806 Yesterday I tried to use spring mvc Frame do file upload , I've made a lot of problems that I shouldn't have ...

  5. utilize spring Of MultipartFile File upload 【 primary 】

    utilize spring Of MultipartFile File upload Mainly depends on jar package spring-web-3.0.6.RELEASE.jar be used  (org.springframework.web.multi ...

  6. SpringMVC+Spring+MyBatis Simple example of integration and image upload

    One . Ideas : ( One ) Dao layer : 1. SqlMapConfig.xml, An empty file will do . File header is required .2. applicationContext_dao.xml. a) Database connection pool b) SqlSessio ...

  7. .NET MVC Upload multiple pictures with parameters (ajaxfileupload)

    Do website , You have to upload pictures . I still remember using it when I did wechat last year WebAPI+ajaxfileupload.js Do a function with parameter upload , Blog address :.NET WebAPI Upload pictures ( Including the attached parameters ...

  8. .net mvc + layui Do picture upload ( Two )—— Use streaming to upload and download images

    Abstract : The last article wrote about a way to upload pictures , It mentions the limitations of that approach , The uploaded file can only be saved in the directory of this project , The file is not accessible in another directory . This is related to the security mechanism of the browser , The browser does not allow users to use any path to access... On the server ...

  9. .net mvc + layui Do picture upload ( One )

    Image upload and display is a common function in Internet applications , Recently, a portal project has several function modules that need to upload pictures . About this part , Originally, the function is not complicated , But there are still some twists and turns in doing it later . Because of lack of experience , Upload several kinds of pictures ...

Random recommendation

  1. Just publish/subscribe Function redis Queue technology in cluster mode ( One )

    Redis brief introduction Redis It's completely open source and free , Is a high-performance key-value database . Redis And others key - value Cache products have the following three characteristics : Redis Support data persistence , Can be stored in memory ...

  2. MVC4 Next DropDownList Usage method

    And MVC3 comparison , The difference is very big : Presentation 1 : public ActionResult Main() { List<SelectListItem> items = new List<Sel ...

  3. php-fpm It won't start libiconv.so.2 Can't find

    service php-fpm start  Starting php-fpm /alidata/server/php/sbin/php-fpm: error while loading shared ...

  4. C# Let the program run automatically under the administrator's permission

    windows 7 and vista Improved system security , At the same time, it needs to be clearly specified that “ Run as administrator ” Can be given to be run software more advanced permissions , Such as accessing the registry, etc . otherwise , When a program running as normal needs to access more advanced system resources , Will throw ...

  5. poj 1742 Coins(dp Multiple backpacks + Multiple optimization )

    Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...

  6. Java How to upgrade the program automatically online

    Sometimes our program needs to connect to the server to detect the new version , If a new version is found, it needs to be downloaded and upgraded automatically . This kind of demand is in the market Linux It's good to say , But in windows How to replace the running program file ? Of course, there's a way , Steps are as follows : 1. Put our program ...

  7. C# take Access Add the data of conditional query in time period to ListView in

    C# take Access Add the data of conditional query in time period to ListView in One . Give Way ListView Control to display the header Add... To the form ListView Space , Set... In its properties :View Property is set to :Detail,Col ...

  8. vector As function return type

    In practice , We often encounter the need to return a sequence of strings or a column of numbers , I used to use arrays to hold strings or numbers in this column , Now we can use it vector To save the data . But when the amount of data is large, use vector It's more efficient than ...

  9. [py][mx]django Use class Write views- Get rid of the trouble of judgment

    modify views Use class Pattern Class pattern writing views - The trouble of judging function pattern is avoided users/views.py from django.views.generic import View clas ...

  10. npm and cnpm(windows) Installation steps

    Reprint :https://blog.csdn.net/wjnf012/article/details/80422313