Servlet container

Hello Friends,

This is the tutorial regarding  java servlet container. This include all the information about how the Servlet Container works in the web server, how it gets the requests and response and how it handles the same and provides the output to be displayed.

Let’s consider the simple example, a client clicks the link on the browser and waits for the result to be displayed on the browser. Now, just when the client clicks the link the request is transferred from the browser to the server and server provide the response and displays the output on the screen, but in all of this there is no role of container mentioned. This is because client is not aware of and neither must he care for what happens at the back end, the only thing he cares is about the results he is showed on the browser. But we will think otherwise and get into it about what actually helps the browser to display the exact result.

As we are talking about the servlets, the web server comes into the picture. Now, when the browser requests for the servlet then the request is passed on to the container (tomcat server) first instead of sending it directly to the servlet. The servlet is already deployed in the container. It’s the container that handles the request from the browser and sends the response back to it.

Let’s have a look how the container handles the request.

1) At first, the client will click the link or URL on the browser and will wait for the response. This is nothing but the request to servlet page. Now, once the link is clicked , the browser will send the Http Request to the Container.

Once the request is with Container, it will create the two HTTP objects for HttpRequest and HttpResponse.

2) After this, the container will look into the requested URL and find out the appropriate Servlet. Then correspondingly, container allocates the thread to process this servlet request and passes the request and response object to it.

3) Once the thread is created, the container calls the Servlet’s service() method.

4) The service() method will call either the doGet() or doPost() method and will create the dynamic response page.

5) This dynamic response is sent back to the container along with the HttpResponse object.

6) Now, the container will generate the HttpResponse from the dynamic page and sent it back to the browser with the requested results.

7) Once the response is sent back to the browser, container deletes the request and response objects which it created earlier, and also deallocates or removes the thread which was allocated to the servlet.

In this way the container handles the requests and responses of the servlets.

Hope this will help you in understanding the container and its working.

Regards,

admin@code2java.com

Related Posts

  • Abstract Class In JAVA

    Hello Friends, This tutorial is for all the Java followers. One of the best feature that is widely used is the term ‘Abstract’. This term can be used as either class or a simple method. An abstract method is any method that is just declared but not instantiated. In other words one can just create…

  • Threads in Java.

    Hello Friends, This is the tutorial for the java developers. One of the most significance feature of core java is Threading. Threading deals with the processing of Threads in a single java program. Let us learn what actually are Threads. *What are Threads? Threads are independently running processes that are isolated from each other upto…

  • Collections In Java.

    Hello friends, Welcome to another tutorial for java followers. You all may have heard about Collections, it is one of the amazing feature in java. Collections are the object for the group of elements, these elements are nothing but the different data structures like as Array Lists, Linked Lists, Vectors, Hash tables,Hash List, Trees, Hash…

  • Maven Installation.

    Hello Friends, This is one of my tutorial for installation of Maven on windows. Maven is a software project management tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information. Maven is an open source community and is a…

  • Jira Plugin Deployment.

    Hello Friends, This is one of the most important tutorial for all the jira developers. You may have heard about the plugins in jira which is a simple Java Archive File with .jar extension. This JAR file contains the class files and auxiliary resources associated with the applications. In Jira we can use Eclipse IDE…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.