1)开发一个web插件。用于上传文件。
2)开发一个FTP工具,不用web上传。
3)用现有的FTP工具。
下面是几款不错的插件,你可以试试:
1)Jquery的uploadify插件。具体使用。你可以看帮助文档。
/*** 报表查询模块 ----文件下载流
* @return
* @throws IOException
*/
public InputStream getInputStream() throws IOException {
InputStream ins = new FileInputStream(zipReports())
return ins
}
/**
* 根据传过来的报表编号压缩文件为zip
* @param response
* @param serverPath
* @param str
* @throws IOException
*/
public File zipReports() throws IOException{
List<StatisticalReport>srclist = new ArrayList<StatisticalReport>()
String[] pks = ids.split(",")
if(pks.length >0){
for(String pk : pks){
String[] str = pk.split("\\|")
StatisticalReport obj = new StatisticalReport()
obj.setCendat(str[0])
obj.setOrgidt(str[1])
obj.setRep_code(str[2])
obj.setCurcde(str[3])
srclist.add(obj)
}
}
StatisticalReport obj = new StatisticalReport()
obj.setReportList(srclist)
//查询要下载的报表文件
List<StatisticalReport>list = statisticalReportService.findReportList(obj)
//获取应用在服务器上的根目录
String path = request.getSession().getServletContext().getRealPath(System.getProperty("file.separator"))
List<File>srcList = new ArrayList<File>()
if(list.size() >0){
for(StatisticalReport statisticalReport : list){
File file = new File(statisticalReport.getFile_path())
if(file.exists()){
srcList.add(file)
}
}
}
Pim_sysUser user = (Pim_sysUser) session.getAttribute(SysConstant.SESSION_USER_DATA)
File zipfile = new File(path + System.getProperty("file.separator") + user.getLogid() + "REPORT.zip")
if(zipfile.exists()){
zipfile.delete()
zipfile.createNewFile()
}
//FileTools.copyFile(, res.getString("help_path"), newFormatFileName)// 上传文件
ZipUtils.zipFiles(srcList, zipfile)
return zipfile
}
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.util.List
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
public class ZipUtils {
/**
* 将多个Excel打包成zip文件
*
* @param srcfile
* @param zipfile
*/
public static void zipFiles(List<File>srcfile, File zipfile) {
byte[] buf = new byte[2048]
try {
// Create the ZIP file
// Compress the files
if(srcfile.size() >0){
// 创建ZipOutputStream类对象
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile))
for (int i = 0i <srcfile.size()i++) {
File file = srcfile.get(i)
FileInputStream in = new FileInputStream(file)
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(file.getName()))// 写入此目录的Entry 创建新的进入点
// Transfer bytes from the file to the ZIP file
int len
while ((len = in.read(buf)) >0) {
out.setLevel(9)
out.write(buf, 0, len)
}
// Complete the entry
out.closeEntry()
in.close()
}
out.close()
}else{
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile))
out.putNextEntry(new ZipEntry(" "))
out.closeEntry()
out.close()
}
// Complete the ZIP file
} catch (IOException e) {
e.printStackTrace()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)