Write file upload forms and controller
Jsp file uploads written in the form:
<form enctype="multipart/form-data" method="post" action="/upload1.do"> 图片:<input type="file" name="photo"><br> <input type="submit" value="上传"> </form>
Write processing file uploads controller, the method of handling file upload need to add MultipartFile types of parameters, MultipartFile itself is an interface, which provides a method of operation of some of the file upload:
- getOriginalFilename ()
to get the file name - isEmpty ()
to determine whether to upload a file, if the file upload is not selected, then the result is true this time - getContentType ()
files get uploaded file type - transferTo (File file)
to upload files to the specified directory - getName ()
Gets the name input values in the form - getBytes ()
Gets byte array to upload files - getInputStream ()
Gets InputStream object to upload files
Another method parameter HttpSession main role is to get the paths from the server used to store the uploaded file.
Details Reference: file upload