File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can one say response is committed!

 
Srikanth shetty Nukala
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
singh santosh
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi srikanth,
You can use response.isCommited() to determine if the response is committed or not.

regards

-santosh
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Srikanth shetty Nukala
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic