What is a Servlet?
Servlet is described as:
- It is a technology which is used to develop web application.
- It is a class which extends the capabilities of the servers and responds to the request.
- It is an API which gives number of classes and interfaces.
- It is a web component which is deployed on the server to develop web page.
CGI (Common Gateway Interface) this is a technology which enables the server to call a program and pass HTTP request information to the program to process the request. It starts a new process for each request. In comparison with the CGI servlets gives many advantages:
- Portability: Servlets are platform-independent because it uses java.
- Robust: need not to worry about memory leak, garbage collection etc. because Servlets are managed by JVM.
- Performance: for each request servlets creates a thread not process.
- Secure: it uses java language hence it secured.
In a Web Application the position of Servlets is as shown in below diagram.
The following tasks are performing by Servlets:
- Read the sent data by browsers which include form of HTML on a Web page or from an applet.
- Read the HTTP request data sent by the browsers which includes media types, cookies etc.
- The process of generating the results requires connecting to a database, executing an RMI or invoking a Web service or manipulating the response directly.
- Send the data like the document to the browsers. This data document can be any of formats like Excel, binary (GIF images), text (HTML/XML) etc.
- Send the HTTP response to the browsers which includes informing the browsers or clients about the type of document is being returned and caching parameters, setting cookies etc.
In the next part of this guide we will setup our environment to run our example code.