What Is Servlet

By | | Updated : 2021-03-12 | Viewed : 11130 times

What Is Servlet

Web application:

Generally, every application has so many users. So, every user wants to access the application from anywhere in the world. So, to achieve this we should have to implement the web application/distributed application which can be run on the internet or intranet.

Web application is an application will be used for displaying the data. But here web application will generate dynamic response based on the user request. Web application will be executed on the server as Server Program to generate the response. This response will be displayed in the client application as a response i.e., HTML.

In web application there are two type of programmers will be used. One is server-side program (Servlet) will be used for generating the dynamic response. Another one is client-side program (HTML) will be used for presenting the response. Client-side programming languages are HTML, XML and soon. These client programmers will be interpreted and executed in the browser. The server programmes reside in the server but client programmes will be resided the in the browser. So, user no need to install the server programmes.

CGI (Common Gate of Interface):

CGI is used for serving the dynamic response content which resides the in the server. By using this, we can develop the web application to provide dynamic response. It will be used for sending the required response as per user/Client request. Even it is one of server side the program, It has its own disadvantages. It usually will be implemented as script to serve the requested data to the client. CGI script will create a process to serve the data to the client. when compare with servlet, it is very heavy. Earlier, it used to implement in the OS related script. But so many languages are supporting this CGI.

Main Drawbacks Of CGI:

For each request, CGI will create new process to serve the response. But in Servlet, for each request, the Servlet Container creates the thread after serving of response thread will be destroyed. So, when you consider performance factor, the Servlet will give be the best.

Servlet will be executed in the Servlet Container, but CGI will create a new process for severing the response. Servlets are portable and efficient when compare to CGI. Servlet will allow to sharing data and cookies. But CGI will not allow.

Servlet Introduction:

Servlet, is simple java class managed by Servlet container. it will be used for generating the dynamic data. Unlike other java class it has its own life cycle which is handled by container. Servlet has used for providing the dynamic content or data for serving the client request.

Servlet Container/Servlet Engine

Servlet container, is sub part of web-server. Servlet Container is collection program classes which will be used for handling the Servlet and Servlet's life cycle for providing the response. It will listen and communicate to the web-server to provide response for http request.

If you observe the below give diagram, you can understand the web application flow

What Is Servlet

Here Client send the HTTP request to WebServer to fetch the dynamic response. To get dynamic response, WebServer will forward the request container. Servlet Container will handle the Servlet lifecycle (i.e., Servlet API) for getting dynamic response. Once response prepared then container will pass that response to WebServer. Finally, response will be sent to the browser by the Server.

Leave A Reply