---
title: "Session  IllegalStateException"
author: "water84222"
date: "2010-06-15T14:56:57Z"
tags: []
categories: ["企业架构"]
slug: "session-illegalstateexception"
draft: false
lastmod: "2010-06-15T14:56:57Z"
id: 692240
url: "https://onlyLove.iteye.com/blog/692240"
---

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保持一致了。