首页 > 编程语言 > 详细

有时候在操作Session时,系统会抛出如下异常:java.lang.IllegalStateException: Cannot create a session after the response has been committed

时间:2014-07-06 20:38:17      阅读:1157      评论:0      收藏:0      [点我收藏+]

有时候在操作Session时,系统会抛出如下异常

java.lang.IllegalStateException: Cannot create a session after the response has been committed

 

原因1: 

Session 的创建语句: HttpSession seesion = request.getSession(); 之前有Response的输出语句。

应该把HttpSession seesion = request.getSession(); 放在Response的输出语句前面

 

例如:


response.sendRedirect("xxx.jsp");

HttpSession session = req.getSession();

改成

HttpSession session = req.getSession();

response.sendRedirect("xxx.jsp");

 

原因2:

如果使用了Struts2可以在struts.xml中添加一个默认的拦截器:

            <interceptor-ref name="createSession"/>
            <interceptor-ref name="defaultStack"/>

有时候在操作Session时,系统会抛出如下异常:java.lang.IllegalStateException: Cannot create a session after the response has been committed,布布扣,bubuko.com

有时候在操作Session时,系统会抛出如下异常:java.lang.IllegalStateException: Cannot create a session after the response has been committed

原文:http://www.cnblogs.com/Crthas/p/3824687.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!