Good afternoon.
Why an HTTPservlet's life cycle can be managed by a WEB-container?
A WEB-server(for example Apache Tomcat) is able to capture an HTTP request from client, to process and to reply with an HTTP response; a servlet needs a web container(for example Apache Tomcat again) because it has not a main, so we can see servlet engine as "a main" that initializes a servlet(in a nutshell).
Good! Now I don't understand why this thing is possible. When a client sends an HTTP request, if this is the first invocation of that servlet, web container calls init(). Then, it allows to call doGet, doPost(and the other methods). Finally the servlet is destroyed[destroy()]. But how web container do this? What happen inside servlet engine?
****************************************EDIT*******************************************
My question talks about the reason why a servlet engine can manage the cycle of a servlet. The answer is really easy. A servlet engine can manage the cycle of a servlet(so it can call automatically create(), service() and destroy() methods) because servlet has a public interface, javax.Servlet.servlet. This interface declares methods that have a semantic, an accurate meaning:
create() is used just to create servlet
service() is used to handle HTTP methods
destroy() is used to delete the servlet
Programmers can override these methods but they must respect the semantic of method.