JSP Tutorial implementation file download code
/*
1. Support for single file downloads. Supports multiple file zip compression downloads. Multi-File Zip compression allows you to keep or delete replicas on the server. Supports the download of a specific string or byte array with the specified filename.
2. You need to provide response objects during the download process. and choose the Download form.
3. Check before downloading the process to avoid any errors.
4. Error messages are reported when an error occurs during the download process.
5. Japanese system under the file name is Chinese when garbled problem.
6. A relatively cumbersome setting is required before processing.
Set the response object that the implementation download must be.
public void Setresponse (httpservletresponse response)
Set Download mode: 0 for ordinary single file download. 1 for multiple files compressed into a zip package download. 2 for the specified string, such as stitching into the file content provided to the user to download.
public void Setdowntype (int fileType)
Sets the name of the file to display when downloading.
public void Setdisfilename (String fileName)
Set compressed file for temporary save path (path is absolute path) when compressing file download
public void Setzipfilepath (String path)
When compressing file downloads, set whether the server-side generated compressed files are deleted. True Delete; false retention.
public void Setzipdelflag (Boolean b)
When compressing file downloads, set the file path of the file to compress (the path is absolute)
public void Setzipfilenames (string[] fileNames)
When downloading a single file, set the path of the download file (absolute path)
public void Setdownfilename (String fileName)
When the string is generated to simulate downloading, the contents of the file are set. parameter is a string (can be invoked multiple times)
public int setfilecontent (String filecontent)
When the string is generated to simulate downloading, the contents of the file are set. parameter is a byte array (can be invoked multiple times)
Return value: 0 operation is normal; 9 io exception occurred.
public int setfilecontent (byte[] filecontent)
Call this method to end the file content setting when you simulate a download of a string generated file content.
Return value: 0 operation is normal; 9 io exception occurred.
public int Setfilecontentend ()
The main processing function.
Return value: 0 normal processing; 1 response object not set. 2 The file download mode is not set. 3 The file name to display is not set. 4 the file path to download is not set, or the downloaded file path is not present. 9 IO exception.
public int process ()