您的位置:首页 > 其它

多文件同时下载

2008-08-25 15:17 344 查看
一个用IFRAME结合form表单实现的多文件同时下载应用,不过这种方法不推荐使用,不安全,在此只做备份。
实现的js:

<script type="text/javascript">

<%-- down load file --%>

//helper function to create the form
function getNewSubmitForm(i){
var submitForm = document.createElement("FORM");
submitForm.id = "form"+i;
submitForm.method="POST";
document.body.appendChild(submitForm);
return submitForm;
}

//helper function to create the iframe

function createNewSubmitIframe(i){
var Iframe = document.createElement("IFRAME");
Iframe.name = "form"+i+"targetwin";
document.getElementById("iframe").appendChild(Iframe);
return Iframe;
}

//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
var newElement = document.createElement("<input name='"+elementName+"' type='hidden'>");
inputForm.appendChild(newElement);
newElement.value = elementValue;
return newElement;
}

// helper function to create form and download file ,may be can only for ie
function createFormAndDownload(){

var file_id = "";
var str = "";
var istr = "";
var cnt = "";
if(document.mySheet.LastRow>0){

var sRow = document.mySheet.FindCheckedRow(1);
var arrRow = sRow.split("|");
sRow = "";
for (idx=0; idx<arrRow.length-1; idx++)
{
cnt +=idx+"*";
file_id = document.mySheet.CellText( arrRow[idx], 2 );
var submitForm = getNewSubmitForm(idx);
createNewFormElement(submitForm, "FILE_ID", file_id);
createNewFormElement(submitForm, "ACTION", "download");
createNewFormElement(submitForm, "sStatus", "D");
createNewSubmitIframe(idx);
}
cnt = cnt.substr(0,cnt.length-1);

if(cnt==""){
alert("Please select a file to download!");
return;
}
var ss = cnt.split("*");
for(i=0;i<ss.length;i++){

var frm = document.getElementById("form"+ss[i]);
frm.target="form"+ss[i]+"targetwin";
// alert(frm.target);
frm.action="ES0117_04.jsp";
frm.method="POST";
frm.submit();

}

}else{
alert("Please select a file to download!");
return ;
}
}

</script>
<a href="#"><img src="../../image/btn/btn_download.gif"
width="79" height="23" border="0"
onClick="javascript:createFormAndDownload()">
</a>
文件下载处理:

<%@ page language="java"import="java.util.*,java.io.*,com.idhc.es.cmd.ES0123CMD"pageEncoding="UTF-8"%><%
String ACTION = request.getParameter("ACTION");
if(ACTION!=null){
ES0123CMD cmd = new ES0123CMD();
Map map = cmd.downloadFile(request);
byte[] filebyte = (byte[])map.get("file");
String FILE_TYPE = (String)map.get("FILE_TYPE");
String FILE_SAV_NM = (String)map.get("FILE_SAV_NM");
String FILE_SIZE = (String)map.get("FILE_SIZE");
int len = Integer.parseInt(FILE_SIZE);
response.setContentType(FILE_TYPE);
response.setHeader("Content-Disposition","attachment;filename="+new String(FILE_SAV_NM.getBytes("EUC-KR"),"iso8859-1"));
BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream());
output.write(filebyte,0,len);
output.close();
output.flush();
output=null;
}
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐