File download is relatively simple, response set header tells the browser this is a file download and then Getoutputstream write to the designated place to go.
Such as:
Resp.setheader ("Content-disposition", "Attachment;filename=" +new String ("Test". GetBytes ("GBK"), "iso8859-1") + ". jpg" );
InputStream in = This.getclass (). getClassLoader (). getResourceAsStream ("1.jpg");
OutputStream out = Resp.getoutputstream ();
byte[] bytes = new byte[8192];
int len = 0;
while ((Len=in.read (bytes))!=-1) {
Out.write (bytes, 0, Len);
}
Out.flush ();
In.close ();
Out.close ();
File upload no trouble adding a file form field to a JSP the Enctype= "Multipart/form-data" method must be a post
Need to import two packages under apache.org in Commons Commons-fileupload-1.3.2.jar Commons-io-2.5.jar
Determine if the request is a file upload
Create a temporary warehouse for the parser to give the parser to the file upload object if it is created
Parsing requests
Determine if the normal form field is normal if it is not file upload processing
See File Upload code for details
File Upload, download