使用struts2实现文件下载

<action name="downloadAction" class="">
<result type="stream">
<param name="contentDispositon">attachment;filename=${filename}</param><!--attachment表示不打开下载,设置文件的名字-->
<param name="inputName">downloadFile</param><!-- 设置读取的方法(在action中的方法对应的getDownloadFile(){}) -->
</result>
</action>

 public InputStream getDownloadFile(){
try{
if(1==number){
this.filename=new String(this.filename.getBytes("gbk"),"8859_1");
return ServletActionContext.getServletContext().getResourceAsStream("/upload/java.txt");
}else{
return ServletActionContext.getServletContext().getResourceAsStream("/upload/....");
}
}catch(Exception ex){
ex.printStackTrace();
} return null;
}
上一篇:基本滤波算法比较 (转载http://blog.sina.com.cn/s/blog_69f2aa5a01014du5.html)


下一篇:WCF技术剖析之二十五: 元数据(Metadata)架构体系全景展现[元数据描述篇]