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
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
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
Joined: Jan 21, 2002
thanks peter & anthony the messages are great helps to me to understand the topic. tony
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 ]
Joined: Aug 30, 2001
Peter den Haan
Joined: Apr 20, 2000
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