What is a Servlet ?
A Servlet is a Java class that runs within a web container in an application server, servicing multiple client requests concurrently forwarded through the server and the web container. The web browser establishes a socket connection to the host server in the URL , and sends the HTTP request. Servlets can forward requests to other servers and servlets and can also be used to balance load among several servers.
A browser and a servlet communicate using the HTTP protocol (a stateless request/response based protocol). A servlet receives 2 Objects when it accepts a call from its client. A “ServletRequest”, which encapsulates client request from the client and the “ServletResponse”, which encapsulates the communication from the servlet back to the client.
In addition to both HTTP request and response, HTTP headers are informational additions that convey both essential and non-essential information.
For example: HTTP headers are used to convey MIME (Multipurpose Internet Mail Extension) type of an HTTP request and also to set and retrieve cookies etc.