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

时间:2014-07-06 20:38:38   收藏:0   阅读:298

有时候在操作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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!