Java Tutorial - Java Script : Putting the Pieces Together

Java Tutorial - Java Script :

Putting the Pieces Together


Now that you’ve got a handle on the different pieces of the architecture, here’s how those pieces work together:
1. A request comes in to a Web server.
2. If the requested URL is for a servlet, the Web server sends the request on to the servlet container.
3. The servlet container locates the servlet referenced by the URL.
4. If the servlet has not been initialized, the container executes the servlet’s init() method. It does this only once during a servlet’s lifetime in the container. This allows the servlet to generate dynamic content without repeating the initialization process.
5. The container executes the service() method of servlet. In most servlets (based on the HttpServlet class), the service method will then call the doGet() or doPost() method on the HttpServlet.
6. The servlet does whatever application processing it needs to do to generate the response. This may include connecting to databases or invoking Enterprise Java Beans for example.
A servlet must implement the javax.servlet.Servlet interface. The container calls the methods defined in this interface to manage the servlet’s life cycle. The init() and service() methods mentioned previously are two of the methods defined by the servlet interface