Eclipse IDE- Servlet Program

You need to follow the following steps in order to create a Servlet in Eclipse:

  • Create a web project
  • Create a Servlet
  • Start Tomcat server and deploy project


  1. Eclipse IDE for Java EE Developers(download link)
  2. Apache Tomcat 6.0/7.0(download link , choose “32-bit/64-bit Windows Service Installer” to download from this link and install it by double click on the “.exe” file contained in archive)
  3. Once you are done with installation of Tomcat, remember not to run it at the same instance. As it will get conflicted later with Eclipse, when we deploy our project. Hence make sure that Apache services are stopped

Create a web project:
Select from the menu File –> New –> Dynamic Web Project.

Enter “FirstServlet” as your project name. Click on “NewRuntime” button and select “Apache Tomcat v6.0”.

Click “Next” button.

Click “Next” button.

Click on “Finish” button

Create a Servlet:
Select from the menu File –> New –> Servlet

Write “MyServlet” in the ‘Class Name’ field and then Click ‘Next’ button.

Now in case you want to specify deployment descriptor (web.xml), you can do this here and then Click ‘Next’ button.

Click on “Finish” button

Now you will get something like this

Now remove all that coding and replace it with

import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends HttpServlet
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
		response.setContentType("text/html"); // informing the client that which format of data/response will be send
		PrintWriter out= response.getWriter(); 
		out.println("<hr>HELLO SERVLET</h3>"); // printing on the client



Start Tomcat server and deploy project:
Right click on the project ‘FirstServlet’ and select from context menu ‘Run As’ –> ‘Run on Server’

Select the existing tomcat server
Click “Finish” button.
FirstServlet will get deployed.

Press CTRL+F11, to run web application,

Click “Finish” button.
And you will see the output as