Reputation: 41
When does a servlet container calls the methods doPost / doGet? Does it wait to receive the complete request from the web client before it starts processing it. OR it invokes the methods (doPost or doGet), just after receiving the HTTP headers and the method (POST, GET etc) of the HTTP request is identified?
My question is quite the same to the one asked in the below link: Does servlet engine read the whole request before calling a servlet?
But in addition to that, assuming that the servlet container will invoke the method doPost / doGet immediately after identifying the HTTP method and the content-length, what happens if the web client terminates before the full HTTP request is sent to the webserver/servlet container. How will the servlet thread be aware that the request received is not complete.
Upvotes: 2
Views: 696
Reputation: 3428
Well I don't think the full content is received, what you get is a stream which you can read the content from.
How will the servlet thread be aware that the request received is not complete.
Well you have the content length, so that is how much the container will have to read from the stream when requested, and if the stream is unavailable for some reason the container will throw an exception. It is the same if the client disconects after you received all the data; until you write back, you wont know that the client has disconected.
Upvotes: 3