SSH后台生成流然后发给前台

来源:互联网 发布:网络虚拟展厅 编辑:程序博客网 时间:2024/06/11 14:14

strus导出文件的常用方法

1.配置strus

<action name="exportDevicesTemplateForExcel" method="exportDevicesTemplateForExcel"
class="deviceAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel;charset=utf-8</param>
<param name="inputName">returnFile</param>
<param name="contentDisposition">attachment;filename="${fileName}.xls"</param>
<param name="bufferSize">1024</param>
</result>
</action>


2.把生成的文件做成输出流

public class ExcelUtil {/** * 将Workbook写入到InputStream *  * @param workbook *            HSSFWorkbook * @param fileName *            String 文件名 *  * */public static InputStream workbook2InputStream(HSSFWorkbook workbook) {// this.setFileName(URLEncoder.encode(fileName, "UTF-8"));InputStream excelStream = null;try {ByteArrayOutputStream baos = new ByteArrayOutputStream();workbook.write(baos);baos.flush();byte[] by = baos.toByteArray();excelStream = new ByteArrayInputStream(by, 0, by.length);baos.close();} catch (IOException e) {e.printStackTrace();}return excelStream;}}


0 0
原创粉丝点击