Servlet Tutorial

Introduction

Servlet is a server side Java based programming language widely used to create dynamic web applications. Servlet runs inside a servlet container.

It is a portable language so, it will not rely only on one type of web servers. Servlets can be seen as an improved variant of Common Gateway Interface (CGI).

Servlet Tutorial

Index Title
Tutorial Servlet Tutorial
Tutorial Life Cycle of Servlet
Tutorial Servlet Packages
Tutorial Web.xml file
Tutorial Servlet Interface
Tutorial ServletRequest and ServletResponse
Tutorial ServletConfig
Tutorial ServletContext
Tutorial RequestDispatcher
Tutorial Session Management
Tutorial HttpSession
Tutorial Cookies
Tutorial URL Rewriting
Tutorial Hidden Form Field
Tutorial Servlet Filter
Tutorial Asynchronous Servlet
Tutorial AsyncEvent and AsyncListener

What is servlet container?

Servlet container is a part of web server used to handle various server side technologies request. Servlet container is used to manage the lifecycle and provide runtime environment.

Common Gateway Interface (CGI)

CGI is an initial server side scripting language used to generate webpages dynamically. Unlike servlets, it is not based on Java. CGI programs can be written in many other programming languages like C, C++ and Perl etc. It has some drawbacks which are overcome by Java servlets.

Advantages of servlet over CGI

Servlet

CGI

Servlets are platform independent.

CGI is platform dependent.

In servlets, each request is handled by a thread which provides better performance.

In CGI, each request is handled by a process that degrades the performance.

As servlets are based on Java, they provide more security.

CGI provides less security as its programs are written in programming languages like C, C++ etc.

Servlets can easily handle cookies for session tracking.

CGI is not capable of handling cookie.

Features

Servlet provides various features. Some of them are listed below.

  • Server side: Servlet is a server side technology. So, it is capable to handle server requests and responses.
  • Dynamic: Servlet creates dynamic webpages. So the content of these pages can be updated dynamically with time and requirements.
  • Portable: Java is a platform independent language. So being based on Java, servlets created on one operating system having any web server can easily run on another operating system having any other web server.
  • Secured and Robust: Since Servlet is based on Java programming language so, it are secure and robust like Java.
  • Better performance: Servlet uses thread instead of a process. So, we can perform multiple tasks more efficiently.