Use commons-fileupload to upload files and commonsfileupload
I. Analysis of File Upload principles
1. Prerequisites for File Upload
A. The form method must be post.
B. The form's enctype attribute must be of the multipart/form-data type.
Default Value of enctype: application/x-www-form-urlencoded
Purpose: Inform the server of the MIME type of the Request body
Application/x-www-form-urlencoded: username = abc & password = 123
ServletRequest. getParameter (String name); this method is used to read this type of data.
Multipart/form-data:
2. Use the commons-fileupload component to upload files
A. Copy jar package: commons-fileupload.jar commons-io.jar
B. Implementation Principle
3. garbled Problem
A. garbled characters in common fields
FileItem. getString (String charset); the encoding must be consistent with that of the client.
B. garbled Chinese file names uploaded
Request. setCharacterEncoding ("UTF-8"); encoding must be consistent with the client
4. Specific implementation
The front-end upload. jsp code is as follows <% @ page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">