Practical use of @WebServlet and other annotations

To demonstrate the practical use of servlet annotations, I have created a web application which have two servlets (ProcessingServlet & ForwardingServlet), a listener (HitCounterListener), a filter (HitCounterFilter) and a HTML page (index.html). When the application is deployed, HitCounterListener sets an attribute named hitCount in the application scope to count the no. of hits of the […]

what is a servlet?

The term Servlet has two different meaning in two different contexts. In the broader context, it represents an API of dynamic web application development and in the narrow context, it represent a Java class which is defined using this API for processing requests in a web application. As API, Servlet contains interfaces and classes which […]

Servlet life cycle

Servlet life cycle describes how and when a servlet object is created and initialzed, how it processes requests and how and when it is destroyed by the server. Servlet life cycle is defined by javax.servlet.Servlet interface. Life cycle methods of Servlet interface: init(): This method is invoked by the web server only once, just after […]

How a Servlet is defined?

A servlet class can be defined by directly implementing the Servlet interface or by extending a helper class javax.servlet.GenericServlet provided by servlet API. It is an abstract class, which implements Servlet interface and defines all its methods except service() i.e. In its sub class, an application programmer need to define only the service method. Following […]