`
quanhy5
  • 浏览: 57351 次
  • 性别: Icon_minigender_1
  • 来自: 陕西
社区版块
存档分类
最新评论

response that is already committed 粘粘更健康

阅读更多
[/size]异常一:java.lang.IllegalStateException:Cannot   forward   a   response   that   is   already   committed
异常二:IllegalStateException:response already commited
异常三:IllegalStateException:getOutputStream() has already been called for this request


前言:

  response是服务端对客户端请求的一个响应,其中封装了响应头、状态码、内容(也就是最终要在浏览器上显示的HTML代码或者其他数据格式)等,

  服务端在把response提交到客户端之前,会使用一个缓冲区,并向该缓冲区内写入响应头和状态码,然后将所有内容flush(flush包含两个步骤:先将缓冲区内容发送至客户端,然后将缓冲区清空)。这就标志着该次响应已经committed(提交)。对于当前页面中已经committed(提交)的response,就不能再使用这个response向缓冲区写任何东西  (注:以为JSP中,response是一个JSP页面的内置对象,所以同一个页面中的response.XXX()是同一个response的不同方法,只要其中一个已经导致了committed,那么其它类似方式的调用都会导致 IllegalStateException异常)。



对于异常一:

问题描述:

在执行一段代码后,最后执行request.getRequestDispatcher(跳转页面URL).forward(resquest,response)进行页面跳转时,报了此错

问题原因:

1.在forwar之前,response就已经commit到浏览器端了。

导致response commit的原因包括:forward, redirect, flushBuffer

2.前两个原因都是指在forward之前就已经进行了页面跳转动作(forward, redirect)。

至于flushBuffer,每一个JSP页面都有一个缓冲区,默认的缓冲区大小为8KB,如果缓冲区被占满的话,web服务器就会自动将response 进行commit,然后清空缓冲区(即flush),所以再进行页面跳转的时候就会报response已经被commit了。

内置对象out相关方法

public abstract void clear() throws java.io.IOException 清除缓冲区中的内容。如果缓冲区已经被刷新,clear()方法将抛出IOException异常
public abstract void clearBuffer() throws java.io.IOException 清除缓冲区中的当前内容。这个方法和clear()方法的区别是,如果缓冲区已经被刷新,这个方法不会抛出IOException异常
public abstract void close() throws java.io.IOException 刷新缓冲区,关闭输出流。注意,我们在编写JSP页面时,不需要显式地去调用这个方法,因为在JSP容器所生成的代码中会自动包含对close()方法的调用。

public abstract void flush() throws java.io.IOException 刷新缓冲区,两个步骤:1,提交response  2.清空缓冲区
public int getBufferSize()  获得缓冲区大小,同response.getBufferSize()相同
public abstract int getRemaining() 获得缓冲区中未使用的字节数
public boolean isAutoFlush() 判断out对象是否是自动刷新
<%@ page autoFlush="true" %> <%--Default--%>

内置对象response相关方法

response.isCommitted() 确认response是否已经committed
response.flushbuffer(); 同out.flush相同



解决方法:

增大缓冲区大小:     

<%@ page buffer="10kb" %>
[/size]
分享到:
评论

相关推荐

    Cannot forward after response has been committed

    NULL 博文链接:https://m635674608.iteye.com/blog/1510545

    Efficient Proofs that a Committed Number Lies in an Interval.pdf

    FO承诺-CFT协议-范围证明(英语论文)

    应用移植WebSphere问题列表(经验是买不到的)

    Response already committed 删除websphere时,直接删除安装目录下的文件,重新安装websphere时会提示websphere已安装,是否安装副本。 WebSphere应用更新问题 配置oracle jdbc连接时,控制台测试连接成功,但应用...

    HP-dos-AMDbrand.GHO

    HP部分笔记本,重写BIOS或更换主板后,开机提示“WANING!!-Machine is not in committed state!”屏幕出现"主机处于未定义状态"警告。

    Microsoft ASP.NET and AJAX: Architecting Web Applications

    Everybody in the industry is committed to AJAX. Everybody understands the impact of it. Everybody recognizes the enormous power that can be derived from its employment in real-world solutions. Very ...

    a project model for the FreeBSD Project.7z

    During the Core elections in 2002, Mark Murray stated “I am opposed to a long rule-book, as that satisfies lawyer-tendencies, and is counter to the technocentricity that the project so badly needs.”...

    微软内部资料-SQL性能优化3

    If a match is found, it knows that resource is already locked. Some of the resources have “sub-resources.” The followings are sub-resources displayed by the sp_lock output: Database Lock Sub-...

    servlet2.4doc

    A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both. Filters perform filtering in the ...

    HttpWebRequest出错.Section=ResponseHeader Detail=CR

     Section=ResponseHeader Detail=CR 后面必须是 LF The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF 主体意思是微软没有容忍不符合RFC 822...

    微软内部资料-SQL性能优化2

    A reference to an invalid page (a page that is not in your working set) is referred to as a page fault. Assuming the page reference does not result in an access violation, a page fault can be either ...

    55 Read Committed隔离级别是如何基于ReadView机制实现的?l.pdf

    55 Read Committed隔离级别是如何基于ReadView机制实现的?l.pdf

    Beginning ASP.NET for Visual Studio 2015.pdf

    In addition, because Microsoft is committed to supporting ASP.NET developers, it is avail- able in a fully functional free version! This book is an exploration of both ASP.NET Web Forms and MVC. As ...

    temboard-master_python_Committed_

    PostgreSQL offers three levels of transaction isolation: Read Committed

    Beginning ASP.NET for Visual Studio 2015

    Over 38 million websites are currently using ASP.NET, and the new upgrade is already leading to increased adoption. Programmers need to master v6 to remain relevant as web development moves forward. ...

    Committed - Test Version-crx插件

    语言:English (United States) 管理您的NewTab中的每周目标和Todos *警告* 这是一个不稳定的版本,用于测试未发布的功能。 稳定版本:https://chrome.google.com/webstore/detail/commited-newtab-todo-和/...

    中关村在线

    PER_TIME_IN_GC_COUNTER_009_HELP=% Time in GC is the percentage of elapsed time that was spent in performing a garbage collection (GC) since the last GC cycle. This counter is usually an indicator of ...

    How to Speak Tech

    This book would not exist without the lessons I learned from my parents and ... We are committed to making a difference, and the dedication to produce How to Speak Tech is in service of these efforts.

    Committed - NewTab Todo and Goal Manager-crx插件

    NEW *-在侧面菜单中添加了Committed源代码的链接,以便任何有兴趣的人都可以参与! 更新3.0.2-您现在可以选择将待办事项存储在本地存储或Chrome存储中-漏洞修复更新3.0.1-创建待办事项列表-添加待办事项的链接-...

    svn关键词BASE, HEAD, COMMITTED, PREV的深入理解.rar

    svn关键词BASE, HEAD, COMMITTED, PREV的深入理解.rar

    google repo工具

    Prunes (deletes) topics that are already merged. start repo start &lt;BRANCH_NAME&gt; [] Begins a new branch for development, starting from the revision specified in the manifest. The &lt;BRANCH_NAME&gt; ...

Global site tag (gtag.js) - Google Analytics