码迷,mamicode.com
首页 > 编程语言 > 详细

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

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

标签:http   java   使用   io   res   js   

有时候在操作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   java   使用   io   res   js   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!