http://blog.csdn.net/chenghui0317/article/details/9531171

——————————————————————————————————————————————————————————————、

做开发的时候,有时候报错:

java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

字面上是参数异常, 在response已经提交之后 不能发送错误请求。

下面看个例子就一目了然了:

    response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.print("上传成功!上传文件为:"+fileName+"<br/>保存的地址为"+filePath+ "!!");
out.close(); response.sendRedirect("index.jsp");

首先,利用reponse.getWrite()获得输出流对象,close()之后,这里reponse其实已经提交了。注释下面的
sendRedirect代码,执行之后发现response已经进行已经跳转了,只不过url没有发生改变,并且页面上已经有输出上面指定的字符串。

所以当执行上面代码之后 ,reponse 会提交两次,服务器就不知道该怎么办了,所以抛出异常。

解决方案: 去掉out.close()  这里不会因为PrintWriter 输出对象没有关闭而占用资源的。

java.lang.IllegalStateException: Cannot call sendError() after the response has been committed的更多相关文章

  1. 报错:java.lang.IllegalStateException: Cannot call sendError() after the response has been committed(待解答)

    严重: Servlet.service() for servlet [default] in context with path [/20161101-struts2-1] threw excepti ...

  2. java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解读

    源代码: @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Ob ...

  3. java.lang.IllegalStateException: Cannot call sendError() after the response has been committe

    1.问题描述 严重: Servlet.service() for servlet [default] in contextwith path [/OxygenCloud] threw exceptio ...

  4. Java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed

    在使用response重定向的时候,报以下错误:Java.lang.IllegalStateException: Cannot call sendRedirect() after the respon ...

  5. struts2异常记录--java.lang.IllegalStateException

    java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFa ...

  6. java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade

    2012-10-4 19:50:37 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for se ...

  7. myeclipse 无法启动 java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).

    把myeclipse10 按照目录完整拷贝到了另外一台电脑, 另外的目录 原安装目录 D\:\soft\i\myeclipse10 新安装目录 E\:\soft\myeclipse10 双击启动失败, ...

  8. java.lang.IllegalStateException:Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx...}: java.lang.IllegalSta ...

  9. java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead

    java.lang.IllegalStateException: Not allowed to create transaction on sharedEntityManager - use Spri ...

随机推荐

  1. nodetree中 前面复选框禁用插件

    nodetree中 前面复选框的去掉插件 extendTreeCheck.js /** * tree方法扩展 * 作者:小雪转中雪 */ $.extend($.fn.tree.methods, { / ...

  2. httpClient.execute之后一直等待

    可能的原因就是之前执行过一次execute,但是没有释放资源. hrp = httpClient.execute(req); //这句释放资源 hrp.getEntity().consumeConte ...

  3. POJ2186 POPULAR COW

    链接:http://poj.org/problem?id=2186 题意:给你N个点,然后在给你N条有向边,然后让你找出这样的点S,S满足条件图上任意一点都能到达S. 要想满足任意一点都能到达,首先满 ...

  4. HDU 2544 最短路【Bellman_Ford 】

    题意:给出n个节点,m条边,问从起点到终点的最短距离 用bellman_ford,注意是无向图 初学bellman_ford= =一点点理解 因为dijkstra是每次用集合里面的点去更新它们所连接的 ...

  5. OpenERP 安装在Windows server上时间显示不对的解决办法

    这个问题一直困扰着我,后台设置关于时区也参考过一些文章(如改配置文件),显示时间总是差8个小时,后来看了上面的文章后才搞定,虽然那个是解决OE7.0的,但原理一样: server\openerp\ad ...

  6. 几个排序算法的JS实现

    最近找工作,复习一下数据结构的知识,看到排序这一块,顺便动手改了一下. 直接插入排序: 插入排序就是把数据分为有序区和无序区,遍历到的数据和有序区域的数据进行比较,找到要插入的位置,插入位置后的数据做 ...

  7. Ref相关的名词解释

    NV (NOT-VOLATILE),即非易失性,断电不会丢失的存储信息,包括生产信息.客户信息.产品信息等等. 它们都保存在不同(FLASH)分区,并根据不同的分区提供不同的接口.数据结构和管理机制. ...

  8. C与C++的区别无随时更新

    C没有calss类,只有结构体struct class A;  在C中这样写就是错误的,C没有关键字class C的字符指针不会自动开辟内存空间,必须对这个指针指向的地址手动开辟空间后才可以写入数据. ...

  9. 修改Chrome默认搜索引擎为Google.com

    在使用Chrome的时候,Google为增强本地化搜索,或将默认的Google搜索引擎转换为本地语言,如在中国会自动转到google.com.hk,日本会会自动转到google.co.jp,如果你是一 ...

  10. mysql 数据库自增id 的总结

    有一个表StuInfo,里面只有两列 StuID,StuName其中StuID是int型,主键,自增列.现在我要插入数据,让他自动的向上增长,insert into StuInfo(StuID,Stu ...