zoukankan      html  css  js  c++  java
  • Java Web报错:getOutputStream() has already been called for this response解决方案

    今天做了个导出excel表的功能。大概代码如下:

    ouputStream = response.getOutputStream();
    wb.write(ouputStream);
    ouputStream.flush();
    ouputStream.close();
    1
    2
    3
    4
    发现报错

    java.lang.IllegalStateException: getOutputStream() has already been called for this response
    1
    报错原因
    getOutputStream方法用于返回Servlet引擎创建的字节输出流对象,Servlet程序可以按字节形式输出响应正文。
    getWriter方法用于返回Servlet引擎创建的字符输出流对象,Servlet程序可以按字符形式输出响应正文。
    getOutputStream和getWriter这两个方法互相排斥,调用了其中的任何一个方法后,就不能再调用另一方法。

    解决方案有两种:
    在jsp页面里清除response。
    out.clear();
    out = pageContext.pushBody(http://www.my516.com);
    1
    2
    在controller层对应的方法上追加@ResponseBody。
    ---------------------

  • 相关阅读:
    pymongo 学习
    Mongodb 学习
    2个list取交集
    2个list取差集
    yaml 基础
    is 和 ==的区别
    软件测试人员需要掌握的linux命令(二)
    免费翻译API破解(简易翻译工具)
    测试面试解析
    Python之Time模块
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11082211.html
Copyright © 2011-2022 走看看