ITeye博客

action导出文件流的方法

adrianSet · 2013-01-25 09:57 · java / http · 编程语言 · Markdown

action导出文件流的方法 .一) Excel导出

配置文件中:

action中:

ServletActionContext.getResponse().reset(); ServletActionContext.getResponse().setContentType( "application/octet-stream");

typeName=new String(typeName.getBytes("GBK"),"ISO-8859-1");//解决文件中文名称问题 ServletActionContext.getResponse().setHeader("Content-Disposition", "attachment; filename="+typeName+".xls"); out = ServletActionContext.getResponse().getOutputStream();

jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(out); itemChufaService.toExcel(wwb, itemList,title,status,type); out.close();

return SUCCESS;

二)下载文件

action中:

File file = new File(filePath); inputStream = new FileInputStream(file);

return SUCCESS; .

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。