解决struts/spring偶尔出现java.lang.IllegalStateException: Cannot call sendRedirect() after the response的问题
来源:互联网 发布:ubuntu运行apk 编辑:程序博客网 时间:2024/06/05 00:55
最近网站出现一个比较困扰的问题,就是浏览器访问时偶尔出现500错误, 并出现错误堆栈,错误信息如下:Cannot call sendRedirect() after the response has been committed.
google搜索了一下,多数文章提到的原因主要有二:
- 在sendRedirect()之前存在html输出.好象如果小量输出的话并且不刷新(flush)也可以.
- 在sendRedirect()之后应该马上执行return.
参考链接:http://www.newasp.net/tech/53042.html
但我经过反复分析都未发现上述提到的错误代码逻辑.
最后,竟然发现问题的根源是多线程并发导致的问题.
在spring的配置如下:
<bean id=”xxxAction” class=”com.xxx.XxxAction”>
</bean>
上述Bean的配置中需要添加scope=”prototype”参数才可解决,这个参数的意思是让spring针对一个http请求创建一个Action对象.如果没有这个参数,默认的参数是值是singleton,表示是单例.而单例对象在并发请求时导致多线程重入,从而出现标题中的提到的错误提示.
正确的配置如下:
<bean id=”xxxAction” class=”com.xxx.XxxAction” scope=”prototype”>
</bean>
0 0
- 解决struts/spring偶尔出现java.lang.IllegalStateException: Cannot call sendRedirect() after the response的问题
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been commi
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- Java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- 【SSH问题】java.lang.IllegalStateException: Cannot call sendError() after the response has been committe
- java.lang.IllegalStateException: Cannot forward after response has been committed问题的解决
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed错误
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- [异常]java.lang.IllegalStateException: Cannot forward after response has been committed 的完美解决 for nutz
- Cannot call sendRedirect() after the response has been committed
- Cannot call sendRedirect() after the response has been committed
- Cannot call sendRedirect() after the response has been committed
- Cannot call sendRedirect() after the response has been committed
- NSArray去除重复元素的方法
- NYOJ--表达式求值
- 工作中的感悟 (一)初来工作之感
- DAG的最小路径覆盖和二分图的最大匹配
- notepad配色
- 解决struts/spring偶尔出现java.lang.IllegalStateException: Cannot call sendRedirect() after the response的问题
- android美图秀秀--基础
- Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Li
- jquery把数组变为字符串传到服务端并处理
- 学习日志4.14--servlet_JSP
- Android开发中调试日志的输出方法
- ios
- 证明不是哈密顿图的几种方法归纳总结
- linux设备驱动中的并发控制