试图用Apache Poi在Struts1.3下载Excel。 不从第二个请求工作

Struts_config.xml

<action path="/dwnldExcel" type="ntrs.pat.action.DwnExclAction"> </action> 

rightMenuPanel.jsp

 <html:link action="dwnldExcel"><img src="resource/excel_icon.png" height="30" width="30"></html:link> 

xxAction.java

  String serverFilePath = "D:\\workbook8.xls"; //Getting the parameters via session attribute. HttpSession httpSession = request.getSession(); String filterStr = (String) httpSession.getAttribute("filterStr"); LinkedHashMap<String, ArrayList<String>> bzMap = (LinkedHashMap<String, ArrayList<String>>) httpSession.getAttribute("BizMap"); //Write to filesytem in server writetoFile(serverFilePath, filterStr, bzMap); // Read the file from server and stream it File downloadFile = new File(serverFilePath); String mimeType = getServlet().getServletContext().getMimeType(serverFilePath); response.setContentType(mimeType); response.setContentLength((int) downloadFile.length()); response.setHeader("Content-Disposition","attachment;filename="+serverFilePath ); ServletOutputStream out = response.getOutputStream(); FileInputStream inStream = new FileInputStream(downloadFile); byte[] outputBuffer = new byte[4096]; while(inStream.read(outputBuffer, 0, 4096) != -1){ out.write(outputBuffer, 0, 4096); } inStream.close(); out.flush(); out.close(); public void writetoFile(String filePath, String filterStr, LinkedHashMap<String, ArrayList<String>> bizzMap){ HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("BusinessDetails"); HSSFRow row = sheet.createRow(0); Cell cell = row.createCell(columnNum); cell.setCellValue(celvalue); //logic to write the content : : FileOutputStream fileOut = new FileOutputStream(filePath); wb.write(fileOut); fileOut.close(); wb.close(); } 

如果我评论读取和stream部分,一个excel得到正确创build基于服务器的所有请求的filter参数,但随着读取部分 – excel只创build第一个请求,并进一步返回相同的客户端 – debugging显示它不会来到这个特定的行动类本身。 它也没有抛出任何exception。