Struts2下载浏览器没响应,求指教解决问题思路

我看别人之前写的代码,发现仔细比对后一样的,而且与我自己的代码能替换部分进行了替换,发现还是不行。本地有Excel生成,并且数据正常,就是浏览器没反应。
大家先看我代码struts2的配置文件

在看我的代码部分:
`
public InputStream getDownloadFile throws Exception {

 // 第一步,创建一个webbook,对应一个Excel文件 HSSFWorkbook wb = new HSSFWorkbook; // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet HSSFSheet sheet = wb.createSheet"数据表"; // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short HSSFRow rowTitle = sheet.createRowint 0; HSSFRow rowTime = sheet.createRowint 1; HSSFRow rowEmpty = sheet.createRowint 2; HSSFRow row = sheet.createRowint 3; // 第四步,创建单元格,并设置值表头 设置表头居中 HSSFCellStyle styleTitle = wb.createCellStyle; styleTitle.setAlignmentHSSFCellStyle.ALIGN_LEFT; // 标题字体 HSSFFont fontTitle = wb.createFont; // fontTitle.setColorHSSFColor.VIOLET.index; fontTitle.setFontHeightInPointsshort 15; fontTitle.setBoldweightHSSFFont.BOLDWEIGHT_BOLD; styleTitle.setFontfontTitle; HSSFCellStyle style = wb.createCellStyle; // 表头字体 HSSFFont font = wb.createFont; font.setFontHeightInPointsshort 10; font.setBoldweightHSSFFont.BOLDWEIGHT_BOLD; font.setColorHSSFColor.WHITE.index;// 白色头文字 style.setFontfont; // 设置这些样式 style.setFillForegroundColorHSSFColor.DARK_TEAL.index; style.setFillPatternHSSFCellStyle.SOLID_FOREGROUND; style.setBorderBottomHSSFCellStyle.BORDER_THIN; style.setBorderLeftHSSFCellStyle.BORDER_THIN; style.setBorderRightHSSFCellStyle.BORDER_THIN; style.setBorderTopHSSFCellStyle.BORDER_THIN; style.setAlignmentHSSFCellStyle.ALIGN_CENTER; // 内容字体 HSSFCellStyle styleContent = wb.createCellStyle; styleContent.setAlignmentHSSFCellStyle.ALIGN_LEFT; HSSFFont fontContent = wb.createFont; fontContent.setFontHeightInPointsshort 9; styleContent.setFontfontContent; SimpleDateFormat df = new SimpleDateFormat"yyyy-MM-dd"; String tsStartTime = df.formatdatestart; String tsEndTime = df.formatdateend; HSSFCell cellTilte = rowTitle.createCellshort 0; cellTilte.setCellValue"易宝数据报表"; cellTilte.setCellStylestyleTitle; HSSFCell cellTime = rowTime.createCellshort 0; cellTime.setCellValue"查询日期: " + tsStartTime + " - "+ tsEndTime; cellTime.setCellStylestyleTitle; HSSFCell cell = row.createCellshort 0; cell.setCellValue"序号"; cell.setCellStylestyle; cell = row.createCellshort 1; cell.setCellValue"下单时间"; cell.setCellStylestyle; cell = row.createCellshort 2; cell.setCellValue"支付时间"; cell.setCellStylestyle; cell = row.createCellshort 3; cell.setCellValue"商户订单号"; cell.setCellStylestyle; cell = row.createCellshort 4; cell.setCellValue"订单金额"; cell.setCellStylestyle; cell = row.createCellshort 5; cell.setCellValue"收款方名称"; cell.setCellStylestyle; cell = row.createCellshort 6; cell.setCellValue"订单状态"; cell.setCellStylestyle; cell = row.createCellshort 7; cell.setCellValue"支付类型"; cell.setCellStylestyle; cell = row.createCellshort 8; cell.setCellValue"大客户编码"; cell.setCellStylestyle; cell = row.createCellshort 9; cell.setCellValue"PNR"; cell.setCellStylestyle; cell = row.createCellshort 10; cell.setCellValue"起始票号"; cell.setCellStylestyle; cell = row.createCellshort 11; cell.setCellValue"终止票号"; cell.setCellStylestyle; List<Object[]> lstData = SearchRes;// 获取要下载的数据 List list = new ArrayList; int intNo = 1; for Object[] obj : lstData { AirLineDownloadDatas data = new AirLineDownloadDatas; data.setNoString.valueOfintNo; data.setOrderingTimeobj[0].toString; data.setPayTimeobj[1].toString; data.setMerchantOrderIdobj[2].toString; data.setOrderAmountobj[3].toString; data.setPayeeNameobj[4].toString; if obj[5].toString.equals"0"{ data.setOrderState"等待出票"; }else if obj[5].toString.equals"1"{ data.setOrderState"已支付"; }else if obj[5].toString.equals"2"{ data.setOrderState"已出票"; }else if obj[5].toString.equals"3"{ data.setOrderState"已退款"; }else{ data.setOrderTypeobj[5].toString; } if obj[6].toString.equals"0"{ data.setOrderType"会员支付"; }else if obj[6].toString.equals"1"{ data.setOrderType"银行卡支付"; }else{ data.setOrderTypeobj[6].toString; } data.setBigCustomerIdobj[7].toString; data.setPNRobj[8].toString; data.setTicketNoStartobj[9].toString; data.setTicketNoEndobj[10].toString; list.adddata; intNo++; } for int i = 0; i < list.size; i++ { row = sheet.createRowint i + 4;// 从第四行开始 AirLineDownloadDatas dataGet = AirLineDownloadDatas list.geti; // 第四步,创建单元格,并设置值 row.createCellshort 0.setCellValuedataGet.getNo; row.createCellshort 1.setCellValuedataGet.getOrderingTime; row.createCellshort 2.setCellValuedataGet.getPayTime; row.createCellshort 3 .setCellValuedataGet.getMerchantOrderId; row.createCellshort 4.setCellValuedataGet.getOrderAmount; row.createCellshort 5.setCellValuedataGet.getPayeeName; row.createCellshort 6.setCellValuedataGet.getOrderState; row.createCellshort 7.setCellValuedataGet.getOrderType; row.createCellshort 8.setCellValuedataGet.getBigCustomerId; row.createCellshort 9.setCellValuedataGet.getPNR; row.createCellshort 10.setCellValuedataGet.getTicketNoStart; row.createCellshort 11.setCellValuedataGet.getTicketNoEnd; } sheet.setColumnWidthshort 0, 3500; sheet.setColumnWidthshort 1, 5000; sheet.setColumnWidthshort 2, 5000; sheet.setColumnWidthshort 3, 5000; sheet.setColumnWidthshort 4, 3500; sheet.setColumnWidthshort 5, 3500; sheet.setColumnWidthshort 6, 3500; sheet.setColumnWidthshort 7, 2500; sheet.setColumnWidthshort 8, 5000; sheet.setColumnWidthshort 9, 2500; sheet.setColumnWidthshort 10, 5000; sheet.setColumnWidthshort 11, 5000; try { String strFn = java.util.UUID.randomUUID.toString .replaceAll"-", ""; String strOutFn = GlobalParams.strPath + strFn + ".xls";// "/mnt/temp/" // + strFn + // ".xls";// //这个地方在本地都已经生成了文件,数据也正常 FileOutputStream fout = new FileOutputStreamstrOutFn; wb.writefout; fout.close; ActionContext.getContext.getSession.put"file", strOutFn; this.fileName = "Excel" + df.formatnew Date.toString + ".xls"; this.fileName = new Stringthis.fileName.getBytes"GBK", "ISO-8859-1"; //就是这块,debug调试没问题,不知道为啥浏览器就没反应 //而且之前的代码也是这么写的,浏览器是可以的,不知道为啥突然就不行了 File file = new FilestrOutFn; this.fileLength = file.length + ""; InputStream is = new FileInputStreamfile; return is; } catch Exception e { e.printStackTrace; return null; }
}

`
求大神给出解决问题的思路或指教下错误的地方,谢谢!

Content-Type不能配成 text/plain 要配成 application/octet-stream

发表评论

电子邮件地址不会被公开。 必填项已用*标注