Servlets is a Java based technology for server side processing. Other languages or technologies for server side processing are PHP, JSP, node.js, Perl etc.
Definition of a Servlet
A servlet is a special Java class which is dynamically loaded on the server and used to generate dynamic content.
Following are the general steps that happen when a client requests a servlet:
- Client sends a HTTP request from web browser containing a URL with servlet.
- Web server receives the request and forwards the request to application server.
- Using information available in xml (deployment descriptor) the servlet container loads the object appropriate servlet class.
- If required, the servlet retrieves data from database, processes it and sends the response back to web server.
- Web server forwards the response back to the client who sent the request.
Above steps can be illustrated as follows:
Features of Servlets
Following are the features of servlets:
- Platform independent
- Server independent
- High performance (overcomes CGI limitation)
- Highly scalable
CGI vs. Servlets
Following are the differences between Common Gateway Interface (CGI) and Servlets:
Servlet container or servlet engine is a set of objects that provides the runtime environment for servlets. Servlet container manages the life cycle of a servlet.
Following functionality is provided by the servlet container:
- Network services
- Decoding and encoding of MIME based messages
- Servlet life cycle management
- Resource management
- Session management