神雕摩卡之2 2015-01-05 07:28 采纳率: 0%
浏览 2969

java实现流下载为什么没有响应???急急急

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");

    String filename = "a" + df.format(new Date()) + ".xls";
    //File file=new File(filename);
    try {
        ServletOutputStream os = response.getOutputStream();  
        response.reset();  
        // 设置response的Header 
         response.setContentType("application/x-msdownload"); 
         response.setHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));  
         //response.addHeader("Content-Length", "" + file.length());  

        WritableWorkbook wb=Workbook.createWorkbook(os);
        int count=list.size()/65535+1;
        for(int i=1;i<=count;i++){

        WritableSheet ws=wb.createSheet("sheet"+String.valueOf(i), i-1);
        ws.addCell(new Label(0, 0, "标题"));
        ws.addCell(new Label(1, 0, "姓名"));
        ws.addCell(new Label(2, 0, "手机号"));
        ws.addCell(new Label(3, 0, "咨询编号"));
        ws.addCell(new Label(4, 0, "内容"));
        //ws.addCell(new Label(0, 5, "回复内容"));

        int row=1;
        int col=0;

        for(Content c:list){
            if(row==65535) break;
            ws.addCell(new Label(0, row, c.getContentExt().getTitle()));
            ws.addCell(new Label(1, row, c.getAttr().get("name")));
            ws.addCell(new Label(2, row, c.getAttr().get("phone")));
            ws.addCell(new Label(3, row, c.getAttr().get("lawCode")));
            ws.addCell(new Label(4, row, c.getContentTxt().getTxt()));
            row++;

        }

    }
        wb.write();
        wb.close();

        os.close();
       response.flushBuffer();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RowsExceededException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (WriteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
  • 写回答

2条回答

  • 悟空在此 2015-01-05 08:01
    关注

    在 os.close()前
    加个os.flush();

    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多