Spring mvc 解决getOutputStream() has already been called for this response

阅读更多

Spring mvc  导出EXecl 解决getOutputStream() has already been called for this response,

 

能正常导出 ,但是控制台却是报错,在百度里找了好多方法,都不行,如果你看到了,这个方法你可以试试,看看能不能解决   

 

付代码:

 

错误代码:

SwpscService swpscService = (SwpscService) SpringContextUtil.getBean("SwpscService");

mav.addObject("pageobj",swpscService.serachList2(pb));

 

if(pb.getOthersql8().equals("P")){

ExcelExport excelExport=new ExcelExport();

       excelExport.Excelexport(request, response, pb.getResultList());

       

}

 

mav.setViewName("Order_FH_tongji");

return mav;

 

 excelExport.Excelexport的方法里面;

   out = response.getOutputStream();  

           会报错误

 

解决方法:

 

 

 

if(pb.getOthersql8().equals("P")){

ExcelExport excelExport=new ExcelExport();

       excelExport.Excelexport(request, response, pb.getResultList());

       return null;

}

 

mav.setViewName("Order_FH_tongji");

return mav;

        

只需return 一个null; 

 

当然  这个只能随机应变,并不是万能的

你可能感兴趣的:(Spring mvc 解决getOutputStream() has already been called for this response)