Hello World Servlet

A servlet is a small Java program that runs within a Web server. Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol.

in below example I am going to create a servlet extending javax.servlet.http.HttpServlet class which is an abstract class.

Hello World Servlet Example :-

Step - 1

Create a class file inside the dynamic web project as shown in below :-


Step - 2

Complete Java code for Hello Servlet Class :-


Step - 3

Mapping above servlet class inside the "web.xml" file as shown in below:-


Step - 4

Deploying the web project on tomcat server using eclipse

deploy-projectDeploy a web project

Step - 5

Accessing the servlet using below URI:-