action导出文件流的方法
.一) Excel导出
配置文件中:
<action name="itemToExcel" class="itemSetupManager" method="itemToExcel">
<result name="error">/error.html</result>
<interceptor-ref name="defaultComponentStack"/>
</action>
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 name="downLoadGonggaoAtta" class="infoManage" method="downLoadGonggaoAtta">
<result name="success" type="stream">
<param name="inputName">inputStream</param>
<param name="contentType">application/octet-stream;charset=gb2312</param>
<param name="contentDisposition">attachment;filename="${fileName}"</param>
<param name="bufferSize">2048</param>
</result>
</action>
action中:
File file = new File(filePath);
inputStream = new FileInputStream(file);
return SUCCESS;
.
.一) Excel导出
配置文件中:
<action name="itemToExcel" class="itemSetupManager" method="itemToExcel">
<result name="error">/error.html</result>
<interceptor-ref name="defaultComponentStack"/>
</action>
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 name="downLoadGonggaoAtta" class="infoManage" method="downLoadGonggaoAtta">
<result name="success" type="stream">
<param name="inputName">inputStream</param>
<param name="contentType">application/octet-stream;charset=gb2312</param>
<param name="contentDisposition">attachment;filename="${fileName}"</param>
<param name="bufferSize">2048</param>
</result>
</action>
action中:
File file = new File(filePath);
inputStream = new FileInputStream(file);
return SUCCESS;
.