关于java response.resett过不去.的原因是什么

response.reset()和response.resetBuffer()
- 心无止境 - ITeye博客
博客分类:
getResponse的getWriter()方法连续两次输出流到页面的时候,第二次的流会包括第一次的流,所以可以使用将response.reset或者resetBuffer的方法。reset(): Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.resetBuffer(): Clears the content of the underlying buffer in the response without clearing headers or status code. If the response has been committed, this method throws an IllegalStateException.
浏览: 196259 次
来自: 北京
windows 更新的时候,貌似avast会限制流量?
也遇到了同样的问题,是递归调用时preparedStateme ...
java compiler&&Building&g ...
我也遇到这种问题了,纠结,网上说的我试了都不行
不错 张见识了httpServletResponse reset flushBuffer
httpServletResponse reset flushBuffer
编辑:www.fx114.net
本篇文章主要介绍了"httpServletResponse reset flushBuffer",主要涉及到httpServletResponse reset flushBuffer方面的内容,对于httpServletResponse reset flushBuffer感兴趣的同学可以参考一下。
httpServletResponse reset flushBuffer
reset():Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.
该方法必须在response commited之前进行,该方法将buffer中的所有数据清空.
flushBuffer:Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.
该方法被调用后,改response 将被提交.
resp.reset();
&&& &&& System.out.println(&response if commited: &+resp.isCommitted());
&&& &&& resp.flushBuffer();
&&& &&& System.out.println(&response if commited: &+resp.isCommitted());
response if commited: false
response if commited: true
resp.flushBuffer();
&&& &&& System.out.println(&response if commited: &+resp.isCommitted());
&&& &&& resp.reset();
&&& &&& System.out.println(&response if commited: &+resp.isCommitted());
response if commited: true
Jan 7, :25 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet setCookie threw exception
java.lang.IllegalStateException
&&& at org.apache.catalina.connector.ResponseFacade.reset(ResponseFacade.java:310)
&&& at com.myapp1.cookie.WriteCookie.doGet(WriteCookie.java:58)
&&& at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
&&& at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
&&& at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
&&& at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
&&& at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
&&& at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
&&& at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
&&& at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
&&& at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
&&& at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
&&& at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
&&& at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
&&& at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
&&& at java.lang.Thread.run(Unknown Source)
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!
二、互相尊重,对自己的言论和行为负责。
本文标题:
本页链接:response.reset()和response.resetBuffer()
getResponse的getWriter()方法连续两次输出流到页面的时候,第二次的流会包括第一次的流,所以可以使用将response.reset或者resetBuffer的方法。
Clears any data that exists in the buffer as well as the status
code and headers. If the response has been committed, this method
throws an IllegalStateException.
resetBuffer():
Clears the content of the underlying buffer in the response
without clearing headers or status
code. If the response has been committed, this method throws
an IllegalStateException.
response.reset()的使用有一个条件受限:response的任何打开流关闭之后都不能再reset&
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。java写的下载代码不能用qq旋风下载但可以用迅雷下载
- ITeye问答
这是下载的部分代码
& response.reset();
response.setContentType("application/zip");
response.setHeader("Content-disposition", "filename="
+ (new String(dstName.getBytes("gb2312"), "iso8859-1")));
小弟不知道是什么原因造成的,求帮助
问题补充:quxiaoyong 写道那说明了几个问题:
1.迅雷在下载方面确实比QQ要牛。
2.你的代码不具有通用性,即不是所有的下载软件都能下载。
3.具体什么问题,我也不清楚,不过这句response.setContentType("application/zip"); 没问题,我估计可能是
response.setHeader("Content-disposition", "filename="
+ (new String(dstName.getBytes("gb2312"), "iso8859-1"))); 的问题。
现在的问题需要支持qq旋风下载,都不知道该怎么修改
问题补充:貌似还是不行,我现在设置了一下大小:response.setContentLength((int) inFile.length());结果是旋风下载可以下载部分,到后面又不动了,提示文件名被自动修改,不知道该怎么解决
使用attachment而不是inline
改成如下:
response.setHeader("Content-Disposition", "filename="
+ (new String(dstName.getBytes("gb2312"), "iso8859-1")));
用response.setContentLength()把文件的大小设一下再试试看。没指定大小的话,http是用chunked方式传输的,有些比较挫的下载客户端就无法下载。
你可以去阅读以下response的文档,看看对下载这一块是怎么描述的。另外,可以查查http表头的意思。
那说明了几个问题:
1.迅雷在下载方面确实比QQ要牛。
2.你的代码不具有通用性,即不是所有的下载软件都能下载。
3.具体什么问题,我也不清楚,不过这句response.setContentType("application/zip"); 没问题,我估计可能是
response.setHeader("Content-disposition", "filename="
+ (new String(dstName.getBytes("gb2312"), "iso8859-1"))); 的问题。
已解决问题
未解决问题

我要回帖

更多关于 response.reset异常 的文章

 

随机推荐