Servlet Definition:
Servlet is a small java program that runs on Server-side, which serves as an Intermediate layer between HTTP ( Hyper Text Transfer Protocol) request of a Client and Application's in the Web Server.
A Servlet is a small, pluggable extension to a server that enhances the server's functionality.
Servlets are server side components that provide a powerful mechanism for developing server side programs.
Servlets are both server and platform-independent, so they have no performance limitations.
Servlets run entirely inside Java Virtual Machine at Server.
Servlets have become an alternative to CGI ( Common Gateway Interface ), Due to the performance limitations of CGI programs.
Servlets are used for building Interactive web applications.
Difference Between CGI and java Servlet?
The main difference between the two is that, once Servlet is Initialized it stays in the server container until there are no requests to serve ( ie : it performs multiple requests ). where as, a CGI program gets destroyed once it has fulfilled a request.
Since servlet are initialize once and serve many type, this makes them faster over CGI, Because CGI should always go through the initialize state for every request made.
Browser Compatibility?
Since the Servlet runs at server side , It does not check the Browser for Compatibility.Servlets run entirely inside Java Virtual Machine.
Servlet Classes
Servlets uses the classes in the java packages
- javax.servlet
- javax.servlet.http
HTTP Protocols
Servlets are not designed for a specific protocols, but they are often used with the HTTP protocols.
HTTP Servlet are typically used for:
- Dynamic Content ( like getting the result of a database query and returning to the client).
- Process or store the data submitted by the HTML.
- Manage info about an stateless HTTP ( e.g. an online shopping cart manages request for multiple concurrent customers). HTTP as a protocol is stateless.