What is servlet?
Servlet is Server component where 'serv' means server and let' means component. servlet is java file which take request from client, process request and provide html page to client.

why we need servlet?
Servlet is basic fundamental for creating web application in java. Now question arise that why we even need web application? We need web application because web site will provide only static data and in this era of e-commerce no one wants static content. Web application is mixture of billions of user and web server where user can connect to web application with help of wire of wireless network and web server will take client request and return something to client.

As servlet don't have main(), how it works?
If you have created basic program in java then you know that we must have main() in java program which is starting point of any program and which helps you to call methods of class but if you observe servlet we don't have main(). We don't have main() because we have web container. When user request for servlet, server hands request to web container where servlet is deployed.
why we use web container?
One question arise that why we should deploy servlet into web container as it will be extra overhead!! Just because web container will provide many advantages.
1) Translate JSP
In servlet we write java code inside html but JSP allow us to write java code into html. JSP allow easy development of web pages and allow web designer and web developer to work independently. All JSP pages are translated into servlet and web container is responsible for translating JSP into servlet.
2) Servlet lifecycle
when user request for servlet, web container will check whether any instance of servlet is available or not, if not then web container will instantiated new instance of servlet. If instance is already created then web container will create new thread of instance. If web container don't get request for servlet over long period(specified in web container) web container will destroy instance of servlet.
3) Allow to focus on business logic.
You can consider web container as your application assistant who will perform all necessary extra work on behalf of you. Web container allow you to focus on business logic by building serversockets, listen on port and performing all underlying services.
How web container build page?
Servlet are .java file and we need response in .html format. To convert .java file into .html file we use deployment descriptor(web.xml). We can map request to servlet with help of servlet and servlet mapping tag. In servlet tag we specify class name and in servlet mapping tag we have specify url pattern.
Benefits of servlet