这是源码
Stringpath="D:\\java_team.zip";
Filefile=newFile(path);
longsize=file.length();
try{
/**为了解决中文名称乱码问题这里是设置文件下载后的名称*/
StringfileName=newString(file.getName().getBytes("UTF-8"),"iso-8859-1");
/**清空response*/
response.reset();
response.setHeader("Accept-Ranges","bytes");
/**设置文件下载形式*/
response.setHeader("Content-disposition",String.format("attachment;filename=\"%s\"",fileName));
/**浏览器压缩数据的长度*/
response.addHeader("Content-Length",String.valueOf(size));
FileInputStreamin=newFileInputStream(file);
BufferedOutputStreamoutputStream=newBufferedOutputStream(response.getOutputStream());
byte[]b=newbyte[1024];
inti=0;
while((i=in.read(b))>0){
outputStream.write(b,0,i);
}
outputStream.flush();
outputStream.close();
in.close();
}catch(IOExceptione){
e.printStackTrace();
}
这是前台代码
$('#btns').click(function(){
varselectedIds=$("#list2").jqGrid("getGridParam","selarrrow");//得到选中的多行。
varurl="${appName}/personalcredit/datadowmload/zipDownLoad.ajax";
varform=$(".cus-form");
form.attr("action",url);
varinput=$("")
input.attr("type","hidden")
input.attr("name","packet_files")
input.attr("value",selectedIds)
form.append(input);
form.submit();
});
分 -->
|