Servlet realizes the functions of file upload, preview, download and deletion
Servlet realizes file upload, preview, download and deletion for your reference. The specific contents are as follows
1、 Preparation:
1.1 file upload plug-in: uploadify;
1.2 jar package required for file upload: commons-fileupload-1.3 1. Jar and commons-io-2.2 jar
1.3 a jar package is required to convert data into JSON objects: commons-bean utils-1.8 3.jar、commons-collections-3.2. 1.jar、commons-lang-2.6. jar、commons-logging-1.1. 3.jar、ezmorph-1.0. 6. Jar and json-lib-2.4-jdk15 jar
1.4 development tools: I use eclipse and feel free to use it
1.5 directory structure
Note: change uploadify The path of the picture uploaded from the cancelled file in the CSS file
2、 Code display
2.1 client code design
JSP part
JS file
2.2 server side code design
File upload code (fileUpload. JavaE file)
File view code (fileview. Java file)
File download code (FileDownLoad. Java file)
File deletion code (filedelete. Java file)
web. XML code
2.3 code optimization
Process file view (fileview. Java) and set the response file type, which can be replaced by the following sentence
response. setContentType(getServletContext(). getMimeType(fileName) + ";charset=UTF-8");
3、 Effect display
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.