Master java skills

Servlet

What is a web application?

A web application is an application that is accessible over the web. Any user or system can make http requests to that web application and get response. Web components like servlets, jsps, filters constitute a web application. Components like jsps, html, javascript run on the browser whereas servlets and jsps run on web server.

Servlet

Servlet technology is used to develop web applications. It is a component that resides on a server and is used to generate dynamic web content.

Before servlets, there was CGI (Common Gateway Interface) scripting language which was used for the same purpose. It was also a server side programming language. But there were many drawbacks associated with it. Servlets were preferred over it as they were introduced.

What is a servlet?

There is no one exact definition of a servlet. Using various features of servlets, we can understand it.

  1. A servlet is a server side component, written in java, that is used to serve http requests.
  2. Servlets reside on servers and respond to incoming http requests.
  3. Servlets can accept request parameters and generate dynamic content.

Browser-servlet communication

Advatages of servlets

Servlets come with many advantages. Let’s have a look at them.

Portable : Since servlets are created using java, they are portable. They are compatible with almost all operating systems.

Persistent : In the sense, that servlets remain in the memory as long as the application is running. Once a servlet establishes a connection with a database, it can serve all the requests that need data from the same database.

Server independent : Servlets are server independent. You write once, and run on any web server available today.

Support for many protocol : Servlet technology supports many protocols, such as http, ftp, smtp etc.

Extensible : Because written in java, Servlets can be extended as per the requirements.

Secure : Since servlets are server side components and can be invoked by web server only, they acquire all the security measures implemented by the web server. They are also safe from memory management issues.

Fast : Since servelt programs are compiled into byte, they are executed faster than many other scripting languages.