1. Web Server
A web server is basically used to give the response to the request specified by the browser (user). It basically uses HTTP protocol for the transmission of data. eg. A user can request for some page by entering the web address and in turn gets response from the server.
A web server contains the Servlet Container
2. Servlet Container
A servlet container is basically use to generate web pages dynamically with respect to the request received from the web browser. The request is received by the web server and then it is forwarded to web container which loads the servlet to process that request.
Servlet container is the container for Servlets.
3. Servlet
Servlets can be defined as the server side pages residing on the web server inside the servlet container which process the requests for generating a dynamic web page.
Servlet container forward the request to the servlet and it call various methods depending on the request and gives a dynamic response accordingly and response is sent back to the client.
Advantages of servlet:
- It makes use of multithreading for serving various requests. This helps to reduce the traffic since the threads are light weight and it also saves memory.
- Since it is dependent on java, it is platform independent.
Let us discuss about the life cycle of a servlet . There are three phases of that:-
- init() :This method is called to initialize the servlet when it is loaded for the first time by the container for the first request.
- service():This method is invoked upon each request after its initialization. Each request is serviced in its own separate thread. The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request.
- destroy(): This method is invoked when the servlet object should be destroyed. It releases the resources being held.
It shows that all the threads are loaded dynamically by the servlet and it is garbage collected by JVM when no longer needed.
0 Comment(s)