Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How can one say response is committed!

 
Greenhorn
Posts: 20
  • 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.
 
Ranch Hand
Posts: 136
  • 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
 
Ranch Hand
Posts: 230
  • 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
  • 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.
 
Ranch Hand
Posts: 101
  • 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 ]
 
Ranch Hand
Posts: 1026
  • 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).
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic