struts文件下载

来源:互联网 发布:python 贝叶斯分类 编辑:程序博客网 时间:2024/05/16 17:06
private Integer id;

private IUploadService ius = new UploadServiceImpl();

private String fileName;



public InputStream  getInputStream(){

String path = this.servletContext.getRealPath("/upload");

Upload upload;
try {
upload = (Upload) ius.get(Upload.class, id);

this.fileName =  new String(upload.getRealName().getBytes(),"ISO8859-1");

return new FileInputStream(path+File.separator+upload.getSaveName());


} catch (Exception e1) {
e1.printStackTrace();
}
return null;




}

<action name="downAction" class="com.shxt.framework.upload.action.DownAction">
<result type="stream">
<param name="contentDisposition">attachment;filename=${fileName}</param> 
</result> 
</action>