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. PDO(PHP Data Object),Mysqli,以及对sql注入等问题的解决

    这篇是上一篇 http://www.cnblogs.com/charlesblc/p/5987951.html 的续集. 看有的文章提到mysqli和PDO都支持多重查询,所以下面的url会造成表数据 ...

  2. java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.<init>(Ljava/lang/Class;)V

    相应我,是因为你SPRING MVC的包没有加全.你可以新建一个WEB项目.加入SPRING 3.0 的所有包.主要是WEB类的.就可以解决这个问题了.关键就是少包.特别是你的项目原来是SRPING ...

  3. LA 3695 Distant Galaxy

    给出n个点的坐标(坐标均为正数),求最多有多少点能同在一个矩形的边界上. 题解里是构造了这样的几个数组,图中表示的很明白了. 首先枚举两条水平线,然后left[i]表示竖线i左边位于水平线上的点,on ...

  4. HDU 4006 The kth great number【优先队列】

    题意:输入n行,k,如果一行以I开头,那么插入x,如果以Q开头,则输出第k大的数 用优先队列来做,将队列的大小维护在k这么大,然后每次取队首元素就可以了 另外这个维护队列只有k个元素的时候需要注意一下 ...

  5. 20160205.CCPP体系详解(0015天)

    程序片段(01):01.杨辉三角.c 内容概要:杨辉三角 #include <stdio.h> #include <stdlib.h> #define N 10 //01.杨辉 ...

  6. Python中字符串的使用

    这篇文章主要介绍python当中用的非常多的一种内置类型——str.它属于python中的Sequnce Type(序列类型).python中一共7种序列类型,分别为str(字符串),unicode( ...

  7. python工厂方式创建list

    >>> l = list('sdfsdf') >>> l ['s', 'd', 'f', 's', 'd', 'f']

  8. zoj 2105 Lifting the Stone

    题意   裸的计算几何  求多边形重心: #include<iostream> #include<stdio.h> #include<cstring> #inclu ...

  9. 仿Twitter登陆移动背景效果

    有使用Twitter客户端的朋友应该有发现在登录的时候,屏幕上方和下方的云朵图片是不断移动着的,再加上Twitter那支可爱的小鸟在不停的动着,给人的感觉就好像是小鸟在飞翔一样,感觉效果很不错. 我也 ...

  10. 高新服务平台在SUSE系统上重新部署笔录

    安装步骤     ./shutdown.sh 停止tomcat (1) 删除 zjgx 目录下 除bbs 和Demos所有目录和文件 (2)上传zjgx0519.zip 到zjgx目录下 (3)unz ...