getOutputStream() has already been called for this response错误解决

今天做项目需要用导出数据到Excel,数据导出都正常就是后台报getOutputStream() has already been called for this response。

网上查了一下都说response.getOutputStream()和response.getWriter()这两个方法在一次请求中只能调一次,还有说


  1. out.clear();  
  2. out = pageContext.pushBody();  

这是在jsp中写输出容易犯的错误,我是在在action里的不存在这种情况。

每个方法都会返回一个ActionForward对象,而response是ActionForward对象参数,所以就会使response冲突,处理下载或上传的acton方法返回null就可以了





  1.     @RequiresPermissions("account:aLoan:view")
        @RequestMapping(value = "exportExcel", method = RequestMethod.POST)
        public String exportListAloan(ALoan aLoan, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes) {
        exportListAloan(aLoan,request,response,model,redirectAttributes,"债权清单");
        return null;//这里返回null解决 getOutputStream() has already been called for this response错误
        }
      public void exportListAloan(ALoan aLoan, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes,String filename) {
            Page<ALoan> page = new Page<ALoan>(request, response);
            logger.debug("expExcel");
            List<ALoan> list = aLoanService.findList(aLoan);
            try {
                String fileName = filename +"_" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
                new ExportExcel(filename, ALoan.class).setDataList(list).write(response, fileName).dispose();
            } catch (IOException e) {
                addMessage(redirectAttributes, "导出"+filename+"!失败信息:" + e.getMessage());
            }
            page.setGrossList(list);
            model.addAttribute("page", page);
            model.addAttribute("aLoan", aLoan);
        }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值