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。
---------------------
Java Web报错:getOutputStream() has already been called for this response解决方案的更多相关文章
- Java Web报错: GET http://localhost:8080/ 404 (Not Found)
eclipse正常启动tomcat,但是 访问http://localhost:8080 报404错误 搞笑的是我访问服务器中的其他网页也可以打开 报错如下: 解决: 如果这3项都已经变灰色,删除配置 ...
- Java Web报错:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
问题描述: 我们在用Eclipse进行Java web开发时,可能会出现这样的错误:The superclass javax.servlet.http.HttpServlet was not foun ...
- JSON.toJSONString(joinPoint.getArgs())报错getOutputStream() has already been called for this response
nested exception is java.lang.IllegalStateException: It is illegal to call this method if the curren ...
- Oracle EBS Java Applet报错:找不到类
Oracle EBS Home Page可以打开,但是无法打开EBS的Form,查看Java控制台,有错误报出. java控制台报错,如下: Java Plug-in 1.6.0_07 使用 JRE ...
- android studio java工程 报错
作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E-mail: 313134555 @qq.com android studio java工程 ...
- Centos7 JDK安装过程中 解决java -version 报错: bash: /home/jdk1.8.0_161/bin/java: Permission denied
1.执行Linux命令 -----vim /etc/profile 编辑profile 文件,在里面添加: #set java enviroment JAVA_HOME=/opt/JavaHome ...
- debug运行java程序报错
debug运行java程序报错 ERROR: transport error 202: connect failed: Connection timed out ERROR: JDWP Transpo ...
- java @override 报错处理
转载自:http://blog.sina.com.cn/s/blog_9c7605530101kl9r.html 一.java @override 报错处理 做项目的时候,同事那边电脑上编译通过的ja ...
- php通过JavaBridge调用Java类库和不带包的自定义java类成功 但是调用带包的自定义Java类报错,该怎么解决
php通过JavaBridge调用Java类库和不带包的自定义java类成功 但是调用带包的自定义Java类报错,Class.forName("com.mysql.jdbc.Driver&q ...
随机推荐
- 【转】C#里partial关键字的作用
源地址:http://www.cnblogs.com/OpenCoder/archive/2009/10/27/1590328.html
- (四)从输入URL到页面加载发生了什么
一.从输入URL到页面加载发生了什么 1.在浏览器中输入URL 如:https://www.cnblogs.com/loveapple/ URL分成协议.地址.路径三部分 协议:http.https. ...
- 2019南昌邀请赛网络赛:J distance on the tree
1000ms 262144K DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(N ...
- Leetcode初级算法(字符串篇)
目录 反转字符串 颠倒整数 字符串中的第一个唯一字符 有效的字母异位词 验证回文字符串 实现strStr() 数数并说 最长公共前缀 字符串转整数(atoi) 反转字符串 和vector同样的进行sw ...
- jsonp——使用公共接口获取数据
demo: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8 ...
- 013 Roman to Integer 罗马数字转整数
给定一个罗马数字,将其转换成整数. 返回的结果要求在 1 到 3999 的范围内. 详见:https://leetcode.com/problems/roman-to-integer/descript ...
- Eclipse中mybatis的xml文件没有提示,出现the file cannot be validated as the XML definition.....
1.下载dtd文件 2.在eclipse中配置本地dtd文件: Window->Preferences->XML->XML Catalog->User Specified En ...
- set<int> 的用法
博客学习:https://blog.csdn.net/yas12345678/article/details/52601454 介绍一下 *max_element(a,a+n) 求取数组最大的元素 ...
- Vertical roller mill from SBM
Vertical roller mill has many different forms, but it works basically the same. All of these forms o ...
- 高可用数据同步方案-SqlServer迁移Mysql实战
简介 随着业务量的上升,以前的架构已经不满足业务的发展,数据作为业务中最重要的一环,需要有更好的架构作为支撑.目前我司有sql server转mysql的需求,所以结合当前业务,我挑选了阿里云开源的一 ...