多文件同时下载
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;
}
%>
实现的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;
}
%>
相关文章推荐
- PHP 单TXT下载和多个TXT文件打包下载 同时
- Windows下编译同时支持三种位深的x265可执行文件方法,附编译好的结果下载
- 解决jsp下载没有进度条同时解决struts不在页面打开下载文件
- IIS 6 和IE6.0只能同时下载两个文件的问题
- QQ/Foxmail中转文件同时下载人多的解决方法______
- php curl 请求下载文件,以及同时向接口发送参数和文件
- pdf文件下载同时计数
- 系统多种资源文件代码示例(例如一个系统同时具有中文简体,中文繁体,英文,日文等不同资源文件)(示例代码下载)
- ASP.NET中怎么能同时下载多个文件或者一个文件夹?
- Android 多线程断点续传同时下载多个大文件
- 系统多种资源文件代码示例(例如一个系统同时具有中文简体,中文繁体,英文,日文等不同资源文件)(示例代码下载)
- js 同时下载多个文件
- SSRS 实现多个文件同时上传和下载到ReportManager的功能
- 系统多种资源文件代码示例(例如一个系统同时具有中文简体,中文繁体,英文,日文等不同资源文件)(示例代码下载)
- 上传下载文件, 同时部署在webapps下, 而不是项目下,防止重新部署tomcat, 上传文件消失
- 【前端优化】如何将 Internet Explorer 配置为可以同时下载多个文件?
- libcurl同时下载多个文件
- 如何将 Internet Explorer 配置为可以同时下载多个文件?
- Asp.net 同时下载多个文件
- 系统多种资源文件代码示例(例如一个系统同时具有中文简体,中文繁体,英文,日文等不同资源文件)(示例代码下载)