necessary prerequisites for uploading 1.1 files:
A, provide form form ,method must be post
b, the form form enctype must be multipart/form-data
C, provide input type= "file" class of the upload field
1.2enctype Properties
function: Notifies the server of the request body MIME type. (Request message header:content-type effect is consistent)
Optional values:
application/x-www-form-urlencoded ( default ):
Body: name=admin&password=123
Server fetch data: String name = Request.getparameter ("name");
Multipart/form-data:
The server gets the data: therequest.getparameter (String) method gets the specified form field character content, but the file upload form is no longer the character content, but the byte content, so the invalidation
File Upload: Parses the contents of each part of the request body.
Request.setcharacterencoding ("UTF-8"); = Request.getinputstream (); int Len; byte New byte [1024x768]; while (len = Sis.read (b))! =-1) { // output upload file contents System.out.println (new String (b,0, Len)); } Sis.close ();
File Upload and file download