This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Pipeline as Code and have Mohamed Labouardy on-line!
See this thread for details.
Win a copy of Pipeline as Code this week in the Cloud/Virtualization 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

before committing the response

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends,
i find there're many instances in which a methord is demanded to be called before committing the response. could anybody answer me what on earth does it mean by saying "call before committing the response"? what'll happen on the server?
thanks,
tony
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
A response is considered to have been committed if any part of the response has actually been sent to the client. You can check this programmatically by isCommitted() of the HttpServletResponse interface.
There are some methods that you must "call before the response is committed", like setContentType(), because they basically set the parameters that will frame the response. Calling them after the response is, well, committed will throw an IllegalStateException.
-anthony
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The content you generate is buffered (you can adjust the buffer size, by the way). As soon as you have generated more HTML than will fit in the buffer, the buffer contents will be sent to the client. This is called "committing the response".
The important point is that not just the buffer content is being sent - a HTTP response consists of a header (which includes, among other things, the response code and any cookies you set) and a body (the HTML). When the response is committed, the response header will be generated and sent to the client.
This is why you can't call a number of methods once the response has been committed: these methods need to manipulate the response header.
- Peter
 
tony lee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks peter & anthony
the messages are great helps to me to understand the topic.
tony
 
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by Anthony Villanueva
Calling them after the response is, well, committed will throw an IllegalStateException.


I could not understand quite clearly why servlet cannot respond more than once?
I have read that even CGI applications, since it expensive to open each time a session/socket/connection, are able to maintain the old one for continuous use.
[ December 28, 2002: Message edited by: G Vanin ]
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by G Vanin:
I could not understand quite clearly why servlet cannot respond more than once?

How can you respond more than once to a single request? If you need to send back multiple things then your response can use the MIME multipart type or similar.
A single request has by definition a single response. That doesn't mean the communication channel is closed after the response -- not if HTTP 1.1 keepalive is being used -- but that works at the transport level, you're not seeing any of it and it doesn't change the request/response paradigm. It is managed entirely by the container.
- Peter
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I've got it
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic