Servlets do not have a main method, they are under the
control of another java method called the container. Tomcat is an example of a
container, the server hands the request to not only the servlet, but also the
container. It’s the container that gives the servlet the request and the
response, and it’s the container that calls the servlets method.
The containers handle a request when it sees that the
request is for a servlet then the container creates a hhtpServletResponse and
httpServletRequest objects. The container finds the correct servlet based on
the URL in the request, creates or allocates a thread, and passes the request
and the response to the servlet thread. Then the container calls the servlets
Service() method depending on the request and the Service() method calls either
the doGet() or doPost() method. According to the method a dynamic page will be
generated and it will be stuffed into the response object, then the container
converts the response object into a HTTP response.
No comments:
Post a Comment