getOutputStream 和 getWriter方法不能同时共用,具体原因不详。估计是不能同时有两个输出流,不然电脑就爆炸了。
-------JAVA DOCS---------------------------------------------------
getOutputStream
public ServletOutputStream getOutputStream() throws java.io.IOException
Returns a ServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data.
Calling flush() on the ServletOutputStream commits the response. Either this method or getWriter() may be called to write the body, not both.
Returns:
a ServletOutputStream for writing binary data
Throws:
java.lang.IllegalStateException - if the getWriter method has been called on this response
java.io.IOException - if an input or output exception occurred
See Also:
getWriter()
getWriter
public java.io.PrintWriter getWriter() throws java.io.IOException
Returns a PrintWriter object that can send character text to the client. The character encoding used is the one specified in the charset= property of the setContentType(java.lang.String) method, which must be called before calling this method for the charset to take effect.
If necessary, the MIME type of the response is modified to reflect the character encoding used.
Calling flush() on the PrintWriter commits the response.
Either this method or getOutputStream() may be called to write the body, not both.
Returns:
a PrintWriter object that can return character data to the client
Throws:
java.io.UnsupportedEncodingException - if the charset specified in setContentType cannot be used
java.lang.IllegalStateException - if the getOutputStream method has already been called for this response object
java.io.IOException - if an input or output exception occurred
See Also:
getOutputStream(), setContentType(java.lang.String)
分享到:
相关推荐
验证码出现getOutputStream() has already been called for this response错误解决
纠结了半天的 java.lang.IllegalStateException: getOutputStream() has already。这个问题困扰了半天,在网上查阅了大量资料 出这个错误一般就是下面2个.....
NULL 博文链接:https://javal.iteye.com/blog/1993903
NULL 博文链接:https://nethub2.iteye.com/blog/2023937
getWriter() 和Response.getOutputStream冲突
1.在tomcat6.0下jsp出现getOutputStream() has already been called for this response异常的原因和解决方法 在tomcat6.0下jsp中出现此错误一般都是在jsp中使用了输出流(如输出图片验证码,文件下载等),没有...
TelnetClient包,Telnet...然后,可以使用getInputStream() 和 getOutputStream() 方法获取用于通过Telnet连接发送和接收数据的InputStream和OutputStream 。使用完流后,必须调用 disconnect 而不是简单地关闭流。
本资源库提供了一份完整的JAVA客户端发送POST请求的示例代码,可以帮助您快速了解如何使用JAVA客户端发送POST请求,同时也适用于其他HTTP请求类型。 我们的示例代码包括以下主要部分: 创建HTTP连接:使用Java.net...
servlet的response可以对返回的内容和格式进行一些设置。
注意:其中getInputStream和getOutputStream方法均会产生一个IOException,它必须被捕获,因为它们返回的流对象,通常都会被另一个流对象使用。 2.如何开发一个Server-Client模型的程序 开发原理: ...
也就是说当一个客户和服务器完成一次通讯之后下一个客户才可以进来和服务器交互,无法做到同时服务,那么要如何才能同时达到既能相互之间交流又能同时交流呢?很显然这是一个并行执行的问题了。所以线程是最好的解决...
用到多媒体技术(JAVA 多媒体框架JMF),视频和音频用TRP协议传输,用到Socket编程技术,多播技术。网络视频会议首先是基于网络传输的,那么就必然要依托于JAVA网络编程的相关知识。在这基础上,由于相关音频、视频...
手机通过蓝牙连接打印机,从BluetoothSocket中getOutputStream()获取outputStream, 然后设置一下即可
2.2性能需求分析 准确性:在实现此的过程中,我们要考虑到,双方是否能同时地出拳,还要就是如何 去判断,准确地知道哪方是赢家. 简洁性:在实现此的过程中,我们要考虑到,怎样使游戏界面更简单,让人更容易明 白...
基于JAVA的剪刀石头布游戏设计 摘要:本课程设计使用Java语言,运用 java.io包和java.net包及getInputStream()、getOutputStream()等方法,编写出一个能在dos环境中显示出剪刀石头布游戏界面,启动服务器端线程,...
另外提一下根据我对教程的学习和实践,我认为实例有一个错误: 就是最后生成JFreeChart chart报表对象,原来项目上是执行String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session); ...
在Spring Boot中实现Excel的导入导出可以通过POI库来实现,POI是一个开源的Java库,用于处理Microsoft Office格式...将Excel写入响应流: 使用response.getOutputStream()获取输出流,然后将工作簿写入到输出流中.....
import java.io.*; import java.util.*; import java.util.zip.Adler32; import java.util.zip.CheckedInputStream;...import java.util.zip.ZipEntry;...import java.util.zip.ZipInputStream;... FileOutputStream fos...