自己的一个函数,主要是Response的使用,把生成的excel数据导出九可以了 public String exportExcel() { //FileOutputStream fos=null; HSSFWorkbook wbError = new HSSFWorkbook(); HSSFSheet sheetError=wbError.createSheet(); HSSFRow rowHeader=sheetError.createRow(0); rowHeader.createCell(0).setCellValue("Hello"); try { ActionContext ctx = ActionContext.getContext(); HttpServletResponse res = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE); res.setContentType("application/vnd.ms-excel;charset=GBK"); res.setHeader("Content-Disposition","attachment;Filename=message.xls"); OutputStream outStream = res.getOutputStream(); // fos = new FileOutputStream(ServletActionContext.getServletContext().getRealPath("/resources/export.xls")); wbError.write(outStream); outStream.flush(); outStream.close(); return SUCCESS; } catch(Exception ex) { ex.printStackTrace(); return INPUT; } }