request.getSession();
出现IllegalStateException 异常。
查看tomcat 源码
if ((context != null) && (response != null) &&
context.getCookies() &&
response.getResponse().isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteRequest.sessionCreateCommitted"));
}
出现这个异常的原因就是这几种,对于response.getResponse().isCommitted(),就是说当response 提交返回了,
就无法设置cookie,如果创建session前,response 已经提交了,那么这个新的session就无法与cookie保持一致了。