Rather than chasing it at the view end why don't you just call getSession in 
the controller or a filter? Then you have no need of doing anything with any 
buffers  etc.

As to what exception is happening it's the illegal state. Whatever has happened 
up to that point of the processing has flushed the HTTP headers. At that point 
attempting to create a new session is illegal and throws an exception.

-----Original Message-----
From: Brian [mailto:bbprefix-m...@yahoo.com]
Sent: Thursday, September 23, 2010 3:02 PM
To: 'Tomcat Users List'
Subject: RE: In org.apache.catalina.connector.Request.doGetSession, 
java.lang.IllegalStateException: Cannot create a session after the response has 
been committed

Wow. This is what I call "Premium Support"! I was thinking about writing en
email to you, Mark, since I was studying the Tomcat source code and saw your
name there. But thought it would be too direct to write to you. I'm honored
to receive your response, really  :-)

Thanks for the "commited" explanation, but I still have a doubt: Where in my
code do I commit? I don't do it explicitly, so it is happening at some point
automatically but I don't know exactly where/when. If a full buffer is not
the cause, what is it for the commit to happen? In which method/class does
it happen?

I will raise the 8K capacity in the buffer, just in case that is the
problem. That would explain why this problem appears to be "randomic". If
just some pages are too big, that would make the buffer to be full, and then
everything in the sequence you described would happen.

I don't explicitly disable the session creation in my JSPs, so that is not
the problem. I don't call any "flushing" method either.

I still have another doubt: According to your sequence, in step 2 my page is
commited (Maybe because of a full buffer, maybe any other reason I don't
imagine). OK. But in step 3 ("something goes wrong"), I guess you are
talking about these two lines in my log:

        at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp
l.java:791) <----- This takes care of that
        at
org.apache.jsp.WEB_002dINF.pages.ProductsForModel_jsp._jspService(ProductsFo
rModel_jsp.java:1137) <--------Here something goes wrong, and an Exception
is being thrown

It is clear that something goes wrong in my "ProductsForModel.jps" page
(actually, in the java code generated for it), so an Exception is being
thrown and " PageContextImpl.handlePageException()" takes care of it. But
what exception? Is it the " java.lang.IllegalStateException: Cannot create a
session after the response has been committed"? Or is it another one? I
guess it is another one, and that the "cannot create..." exception is being
thrown after that, when executing the service method in the java code that
correspoonds to the JSP error page to which I redirect. But how can I know
what exception raised in my "ProductsForModel.jps" page? It seems that since
the code in the JSP error page didnt work (because of its own exception), it
didn't do its job: to explain what went wrong in the "ProductsForModel.jps"
page.

Thanks a lot!



> -----Original Message-----
> From: Mark Thomas [mailto:ma...@apache.org]
> Sent: Thursday, September 23, 2010 01:11 PM
> To: Tomcat Users List
> Subject: Re: In org.apache.catalina.connector.Request.doGetSession,
> java.lang.IllegalStateException: Cannot create a session after the
response
> has been committed
>
> On 23/09/2010 07:42, Brian wrote:
> > What does "response has been commited" mean? I have a theory: Maybe it
> > means that in the java code that the container generated for my JSP,
> > at least one "out.write()" method has already been used, which means
> > that "It already has started to send html code to the browser". Am I
right?
> > Again, this is a sporadic issue, which drives me crazy!
>
> "committed" means that the HTTP headers have been written to the client
> and no further headers can be sent (note: creating a session requires
sending
> a cookie header to the client - this will be important in a bit). Output
is
> buffered (I think 8k by default - might be 4k) by default so you can still
add
> headers even after some content has been written.
>
> JSPs create sessions by default unless you explicitly disable this.
>
> I suspect the sequence is:
> 1. Your page starts processing
> 2. The page is committed (either it calls flush or the output fills the
buffer so
> it has to flush) 3. Something goes wrong 4. Redirect to error JSP 5. Error
JSP
> tries to create a session 6. Response has been committed so session can't
be
> created 7. You get the error you are seeing
>
> If step 3 occurs before step 2 then everything will work as the response
won't
> have been committed.
>
> Mark
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to