File upload and download
1. Upload
File Upload There are two ways
a means of third-party tools
to upload two, springMVC used to implement the file (this step requires upload the configuration file parser);
Use springMVC Upload
introducing two jar package are (commons-fileupload-1.3.1.jar and commons-io-2.4.jar)
create an entity class
configuration file parser springMVC the upload
form a write page (box type wherein the input note set file) (post request) (also modify properties of the form enctype = 'multipart / form-datais meant the multi-component)
After the written control layer
to obtain the tomcat webapp with the root path of the project
Interception. File extension back
The new file name = name + to create a new file interception. Behind the file extension
After a good new file name can be spliced with the current system used to make the milliseconds value of the new file name
Then create a file, first determine whether the air
if(!file.exists()) {
file.mkdirs();
}
Finally, the value can be placed in the created file folder
2. Download
Written according to their own hotel management system, when the method is as follows
// Specify the file name to download
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition","attachment;filename="+new String("用户表.xlsx".getBytes(),"iso-8859-1"));
It needs to be emptied when necessary buffer cache
with a reset ();