can not create a session after response is commited
2017-12-08 21:35
246 查看
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
been created yet and the EL expression
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
be resolved wherein you're trying to get the session. If the server
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.
------https://stackoverflow.com/questions/10949556/cannot-create-session-after-response-has-been-committed。
这个错误一般在本地难以发生,部署到服务器上回发生。
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
HttpSessionhasn'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
HttpSessionhasn'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。
相关文章推荐
- Request header field sessionId is not allowed by Access-Control-Allow-Headers in preflight response.
- Cannot create a session after the response has been committed
- Cannot create a session after the response has been committed
- Sturts2异常: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.IllegalArgumentException: Window type can not be changed after the window is added.
- 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
- Qt Tcp多线程下QObject:Can not create children that is in different thread 的解决方法
- 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
- Server报错:java.lang.IllegalStateException: Cannot create a session after the response has been commit
- [Exceptions Spring 2] - 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
- java.lang.IllegalStateException: Cannot create a session after the response has been committed