File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes problem in session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem in session" Watch "problem in session" New topic

problem in session

Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
In my application after few min it throws this exception..
java.lang.IllegalStateException: Cannot create a session after the response has
been committed
at org.apache.coyote.tomcat5.CoyoteRequest.doGetSession(CoyoteRequest.ja
at org.apache.coyote.tomcat5.CoyoteRequest.getSession(
at org.apache.coyote.tomcat5.CoyoteRequestFacade.getSession(CoyoteReques

plzzzz help me in solving this problem.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

The session gets set in the the HTTP header, which is the first bit sent to the client. The reposnse is buffered until the buffer is filled and then the header gets sent to the client. At this stage it is too late to tell it you suddenly want a session.

Try calling the session earlier, even if you don't use it. THis will make sure it exists later on.

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
Hi Ahmed,

I have not tested myself but I guess your are probably doing this:


HttpSession session=request.getSession();

You previous out.println() have caused the output buffered flushed automatically (and the response committed).
I agree. Here's the link:
subject: problem in session
It's not a secret anymore!