Detailed explanation of Java Web image upload and file upload examples
Java Web image upload and file upload
Image upload is essentially the same as file upload, and the image itself is also a file. File upload is to upload pictures to the server. Although there are many ways, the underlying implementation is file reading and writing.
matters needing attention
1. The form must write the attribute enctype = "multipart / form data"
2. In order to ensure that the file can be uploaded successfully, the name attribute value of the file control should be consistent with the control layer variable name you submitted,
For example, if the space name is file, you need to define it in the background
private File file; // File control name
private String fileContentType;// Picture type
private String fileFileName; // file name
1. JSP page
1. Controller to submit page data
This is to upload files by copying, and there are other ways
Method 2
In addition to single image upload and multi image upload, the principle is the same
Thank you for reading, hope to help you, thank you for your support to this site!