Upload file simply with Spring MVC

Wednesday, December 9th, 2015 (0 Comment)

We will create spring mvc project simply with upload file function. result simple as following image:

page upload

page upload

Step 1: you create a upload file project with structure as below

upload project

upload project

  • uploads folder: we add this folder to storing files uploaded

Step 2: config maven with porn.xml and some xml files:

porn.xml: add commons-fileupload library

config-upload.xml: this file to config maximum size to upload and use multipart/form-data

  • line 14: set maximum size to upload file is 10M

servlet-context.xml: mapping folder upload

  • line 12: mapping to uploads folder to permit page get link and show image uploaded

web.xml: the same as previous article

  • line 18: load config-upload file

Step 3: modify controller class to handle upload page

HelloWorldController.java:

  • line 25: use ServletContext to get real path of file uploaded

Step 4: edit screen page

hello.jsp:

  • line 19: use attribute enctype=”multipart/form-data” permit upload file

index.jsp: redirect to hello page

Finally, you build project upload file and run.

Tags: , ,

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Leave a Reply

Your email address will not be published. Required fields are marked *