aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How can one say response is committed! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How can one say response is committed!" Watch "How can one say response is committed!" New topic
Author

How can one say response is committed!

Srikanth shetty Nukala
Greenhorn

Joined: Apr 07, 2006
Posts: 20
Headers set after the response is committed will be IGNORED by the servlet container.

How can one say whether a response is committed or not, is there any call to a specific function inside servlet code.

Also it has dependencies from sendRedirect(), sendError() and setStatus().

Someone please clarify this.


Regards,<br />SCJA<br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD or SCEA - coming soon!
singh santosh
Ranch Hand

Joined: Jan 13, 2006
Posts: 136
Hi srikanth,
You can use response.isCommited() to determine if the response is committed or not.

regards

-santosh
Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
If your question is "when all do we say that the response is committed?", then ...

Yes! The answer is also linked with sendError and sendRedirect too. When you send error it means that you have already given some response to that request. Same holds good for send redirect too. In these cases, control is no more with in the servlet from which you issued either of the commands.

Even when we do a flush or close on the output stream or print writer object, the response is committed. In these cases, you do still have your control in this servlet. However, setting some status in the response header like contentType et al, will not have effect on the response.

To others ... Am I right? Can experts comment?

Regards,
Mani


Regards,<br />Mani<br />SCJP 1.4 (95%)<br />SCWCD 1.4 (94%)
Srikanth shetty Nukala
Greenhorn

Joined: Apr 07, 2006
Posts: 20
hi manikandan,

I have come thru something sayin a setStatus clears the output buffer and a sendError commits the response and both these functions result in illegalstateexception if response is already committed.

correct me if i am wrong..also sendRedirect has some dependency whether a response is committed or not.
Saurabh Chaubey
Ranch Hand

Joined: Oct 16, 2005
Posts: 101
Hi srikanth,

I have come thru something sayin a setStatus clears the output buffer and a sendError commits the response and both these functions result in illegalstateexception if response is already committed.

correct me if i am wrong..also sendRedirect has some dependency whether a response is committed or not.

I am not sure if the setStatus method will throw a IllegalStateException if the response is already committed as setStatus only sets the status codes in the response,but sendError will surely throw this exception.

Also if we commit response before calling sendRedirect than it will throw an IllegalStateException.
Please correct me if I am wrong.
Regards,
Saurabh
[ May 03, 2006: Message edited by: Saurabh Chaubey ]
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

Also if we commit response before calling sendRedirect than it will throw an IllegalStateException.
Please correct me if I am wrong.



Yes you are correct.


How do we call sendRedirect() method?

Using response object. If the response object is already send to the client(response committed) then how can we call any other method using response object. You will end up getting a runtime exception(IllegalStateException).


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
 
jQuery in Action, 2nd edition
 
subject: How can one say response is committed!