Path refers to the paths of the files you want to download.
File File = new file (path);
Gets the file name.
String filename = File.getname ();
filename = urlencoder.encode (filename, "UTF-8");
Download the file in the form of a stream.
InputStream fis = new Bufferedinputstream (new FileInputStream (path));
byte[] buffer = new byte[fis.available ()];
Fis.read (buffer);
Empty response
Response.reset ();
Set the header of the response
Response.AddHeader ("Content-disposition", "Attachment;filename="
+ filename);
Response.AddHeader ("Content-length", "" "+ File.length ());
OutputStream stream = new Bufferedoutputstream (
Response.getoutputstream ());
Response.setcontenttype ("application/vnd.ms-excel;charset=gb2312");
Stream.Write (buffer);
Stream.flush ();
Fis.close ();
Stream.Close ();
Note: The browser can only be submitted as a form to download prompts, Ajax submissions will not have browser download prompts
HttpServletResponse Setup Download file