FileOutputStream struts.xml部分:
<action name=
"documentMulti_download"
class
=
"com.yourCompany.document.DocumentMultiDownload
>
<interceptor-ref name=
"defaultStack"
/>
<interceptor-ref name=
"execAndWait"
>
<!-- 出现等待页面的延迟时间-->
<param name=
"delay"
>
1000
</param>
<!-- 轮询完成情况时间-->
<param name=
"delaySleepInterval"
>
100
</param>
</interceptor-ref>
<result name=
"wait"
>/client/document/wait/index.jsp</result>
<result name=
"success" type="stream">
<!--指定文件下载类型 application/octet-stream默认值可以下载所有类型-->
<paramname="contentType">application/octet-stream;</param>
<!-- 指定下载的文件名和显示方式 ,但注意中文名的乱码问题,解决办法是:进行编码处理,一般为ISO-8859-1-->
<!--contentDisposition是文件下载的处理方式,包括内联(inline)和附件(attachment),默认是inline, 使用附件时这样配置
<paramname="contentDisposition">attachment;filename="${fileName}"</param>
<!--由getDownloadFile()方法获得inputStream-->
<paramname="inputName">downloadFile</param>
<!-- 指定下载文件的缓存大小-->
<paramname="bufferSize">2048</param>
</result>
</action>
Action 部分:
private FileOutputStream downloadFile;
public String execute()throws Exception
{
//读取文件部分
return SUCCESS;
}
public FileOutputStream getDownloadFile(){
return downloadFile;
}
等待页面主要部分(wait.jsp):<!-- 定时刷新.用于转跳成功页面 -->
head部分:
<META HTTP-EQUIV=
"Refresh"
content=
"2"
;url=<s:url includeParams=
"all"
/>"/>
<script type="text/javascript">
document.onreadystatechanged = function(){
if(document.readyState = 'complete'){
//加载完成时设定计时函数,这个很关键
//设定的延迟时间要比刷新时间长,当完成准备下载文件完成后将会停留在本页面,这个延迟时间将会起作用;
//否则自动刷新起作用,将会重载本页面,上一个setTimeout将会失效。从而实现准备好下载文件后页面跳转的功能
setTimeout(function(){
window.location.href='../index.jsp';
},3000);
}
}
</script>
body部分:
如果长时间没有跳转请点击这里 <a href=
"<s:url includeParams="
all
"/>"
>
Click Here</a>