Cannot create a session after the response has been committed
2013-08-12 09:52
876 查看
有时候在操作Session时,系统会抛出如下异常
java.lang.IllegalStateException: Cannot create a session after the response has been committed
之所以会出现此类问题是因为我们在Response输出响应后才创建Session的。
(因为那时候服务器已经将数据发送到客户端了,即:就无法发送Session ID 了)
解决办法:
你只需要在你的程序中将创建访问Session的语句【request.getSession()】提前至Response输出数据之前就好了。
例如改成下面的写法OK:
ServletOutputStream out = response.getOutputStream();
// 最好这样紧挨着 response.getOutputStream()
HttpSession seesion = request.getSession();
seesion.setAttribute("xxx", rand);
// 输出数据
out.print("<h1>hello</h1>");
out.close();
http://hi.baidu.com/matrix286/item/63085d33459a0027b3c0c565
java.lang.IllegalStateException: Cannot create a session after the response has been committed
之所以会出现此类问题是因为我们在Response输出响应后才创建Session的。
(因为那时候服务器已经将数据发送到客户端了,即:就无法发送Session ID 了)
解决办法:
你只需要在你的程序中将创建访问Session的语句【request.getSession()】提前至Response输出数据之前就好了。
例如改成下面的写法OK:
ServletOutputStream out = response.getOutputStream();
// 最好这样紧挨着 response.getOutputStream()
HttpSession seesion = request.getSession();
seesion.setAttribute("xxx", rand);
// 输出数据
out.print("<h1>hello</h1>");
out.close();
http://hi.baidu.com/matrix286/item/63085d33459a0027b3c0c565
相关文章推荐
- Cannot create a session after the response has been committed
- 关于我碰到的Cannot create a session after the response has been committed
- java.lang.IllegalStateException: Cannot create a session after the response has been committed
- [Exceptions Spring 2] - Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- java.lang.IllegalStateException: Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed错误的原因
- java.lang.IllegalStateException: Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed 响应提交后无法创建会话
- java.lang.IllegalStateException: Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed解决方案
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed