java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
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的更多相关文章
- 报错: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 ...
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解读
源代码: @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Ob ...
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committe
1.问题描述 严重: Servlet.service() for servlet [default] in contextwith path [/OxygenCloud] threw exceptio ...
- Java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
在使用response重定向的时候,报以下错误:Java.lang.IllegalStateException: Cannot call sendRedirect() after the respon ...
- struts2异常记录--java.lang.IllegalStateException
java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFa ...
- 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 ...
- 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 双击启动失败, ...
- 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 ...
- 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 ...
随机推荐
- 同步synchronized用法
今天在高人的指导下,对同步synchronized用法有了更高一层的理解,非常感谢他的无私奉献.在此把代码贴出来方便日后查阅. publicclass SfServlet { privatestati ...
- 不同浏览器JS获取浏览器高度和宽度
摘自:http://blog.csdn.net/lai_gb/archive/2009/07/04/4320956.aspx IE中: document.body.clientWidth ==> ...
- linux下使用svn
安装:apt-get install subversion CHECKOUT 将文件checkout到本地目录 svn checkout path(path是服务器上的目录)例如:svn checko ...
- core--线程同步
[同步(tóng bù)synchronous;sync;synchronism;synchronization 指两个或两个以上随时间变化的量在变化过程中保持一定的相对关系.]这是百度百科对&quo ...
- 利用RunTime解决由NSTimer导致的内存泄漏
NSTimer使用场景 用NSTimer来实现每隔一定时间执行制定的任务,例如最常见的广告轮播图,使用NSTimer实现这个功能很简单代码如下 NSTimer *_timer; _timer = [N ...
- BZOJ 3391 Tree Cutting网络破坏
不想写. #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> ...
- 【Java】MD5加密
package sdfg; import java.math.BigInteger; import java.security.MessageDigest; import java.security. ...
- android 语言切换过程分析
android 语言切换过程分析 2014-02-27 18:13 1207人阅读 评论(0) 收藏 举报 语言切换android语言切换android改变语言 最近在看一个bug,系统切换语言后,本 ...
- [转载] ubuntu Authentication failure
ubuntu的root用户默认是禁止的,需要手动打开才行.事实上ubuntu下的所有操作都用不到root用户,由于sudo的合理使用,避免了root用户下误操作而产生的毁灭性问题.root账号启用方法 ...
- 【转】使用oschina的git服务器
原文网址:http://blog.csdn.net/zengraoli/article/details/24975551 1.概要 其实oschina的git服务器与github的差不多,不过既然是中 ...