Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes when exactly response is commited? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "when exactly response is commited?" Watch "when exactly response is commited?" New topic
Author

when exactly response is commited?

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3829


It shows an IllegalStateException on browser.
Why because response is commited before forwarding second time.

But where exactly response is commited???
I never called flush() method and the second way is if buffer automatically fills then it writes content to stream (sent information to client), but I don't think that buffer is filled here...

(And if stream is unbuffered then it would have given error at the first forward itself, but this is also not the case)


Thanks.
[ May 26, 2006: Message edited by: Bear Bibeault ]
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
I think JSP compiler generates the code to commit the response at the end of service method. So when you forward for the second time, the forward method throws IllegalStateException since the response is committed.

We never do ourselves of commiting the response, it usually taken care by the container.


Manesh
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3829
Originally posted by Dilip Kumar Jain:
I think JSP compiler generates the code to commit the response at the end of service method. So when you forward for the second time, the forward method throws IllegalStateException since the response is committed.

We never do ourselves of commiting the response, it usually taken care by the container.


If container generate 'response commiting code' just before the end of service() method then this code anyway will be executed after 'second time forward code'...
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
before the end of service code

I meant for sevice() menthod second jsp file (b.jsp).

After forwarding for the first time to b.jsp (the response will be commited after this), The execution will resume in service method of a.jsp. The second call to forward method will throw an IllegalStateException , resulting halt in execution of service method in a.jsp.

I think this clears your doubt.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3829
Originally posted by Dilip Kumar Jain:

I meant for sevice() menthod second jsp file (b.jsp).

After forwarding for the first time to b.jsp (the response will be commited after this), The execution will resume in service method of a.jsp. The second call to forward method will throw an IllegalStateException , resulting halt in execution of service method in a.jsp.

I think this clears your doubt.


Thanks Dilip.
Got it.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: when exactly response is commited?
 
Similar Threads
forward happens before service() finishes
Enthuware Question ID: 1074483088830
Include Statements
Still confused of forward()
JWebPlus Q