can not create a session after response is commited

can not create a session after response is commited

这个错误一般在本地难以发生,部署到服务器上回发生。

1.getsession()放在了response提交后面

2.getssion(true),没有session会创建session,访问量稍大时,在多线程环境,单例模式下(Spring默认创建bean的单例的,做权限管理用拦截器时,HandlerInterceptor也是单例),可能会出现response提交了,session再创建,因此不能用true

3.response返回数据是有缓存限制的,具体参考下面文章,当缓存超出限制是就会自动提交的

You shouldn't be doing business job in getters. Do it in the bean (post)constructor instead.

Your concrete problem is caused because you're requesting a relatively large page on a fresh new browser session for which the server HttpSession hasn't been created yet and the EL expression #{equityBean.scripList} is referenced relatively late in the page.

The response buffer is by default 2KB and when it overflows due to a large response, then it will be committed. This means that all response headers will be sent and that first ~2KB of the HTML output will be sent. Then, after that point, the EL expression #{equityBean.scripList} will be resolved wherein you're trying to get the session. If the server HttpSession hasn't been created yet at that moment, then the server needs to set a cookie in the response header in order to maintain it for subsequent requests. But that's of course not possible if the response has already been committed. Hence this exception.

As said, just do the job in bean's (post)constructor instead. Or just inject it as managed property.

@ManagedProperty("#{type}")
private String type;
------https://stackoverflow.com/questions/10949556/cannot-create-session-after-response-has-been-committed。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值