Servlet example eclipse – How to Create Hello World Servlet Example using Eclipse IDE with Tomcat 7? | Servlet Hello World Example in Eclipse IDE with Tomcat

Servlet example eclipse: This tutorial will give you insight into how to run a servlet class that prints the “Hello World” String in the Browser. Here we are going to use the Eclipse IDE to develop code and will run the code in Tomcat Webserver. Creating Servlet in IDE Environment will save you from doing a lot of work. We have outlined the steps to be done in order to create a Hello World Servlet Example using Eclipse IDE in detail.

Tomcat Servlet using Eclipse IDE

For creating a Hello World Servlet Example using eclipse IDE with tomcat 7, you just need two things:

i) Download and install Eclipse IDE for Java EE developers.

Download Eclipse IDE: eclipse ide for java ee developer

ii) Download and install the Apache Tomcat server

Download Tomcat Server:
After download and install Eclipse IDE for Java EE developer and Tomcat Server, you will be able to create a Hello World Servlet Example using Eclipse IDE.

Do Refer:

1. Create a Dynamic Web Project

To create a Dynamic web project open eclipse ide → Go to menu → New → Dynamic web project.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 1

Write your project name and click on next.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 2

Click on the next button

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 3

check on generate web.xml and click on the finish button.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 4

Once you click on the finish button, your Eclipse IDE will automatically create a dynamic web project as follows

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 5

2. Create a Servlet Class

After creating a dynamic web project the next step is to create a servlet class. right-click on your project → New → Servlet

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 6

Write the package name in the java package field and class name in the class name field and then click on next.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 7

You can mention the URL mapping in the following screen(web.xml) and click on next.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 8

Click on the finish button.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 9

On Clicking the finish button, your Eclipse IDE will generate a servlet class depending on the configuration provided in earlier steps as under.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 10

3. Write your Custom Code

Write down your code in doGet() method and call to setContentType() establishes the MIME types of the HTTP response. In this program,the MIME type is text/html.Next the getWriter() method obtains a PrintWriter. Later use println() to write some HTML code as HTTP response.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 11

4. Run your Servlet Code

In Order to run your Servlet code right-click on your project → Run As → 1 Run on Server.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 12

Choose the existing Tomcat Server and then Click on the finish button.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 13

5. The Output on Browser

Your Eclipse IDE will generate output on your own browser and print “HELLO WORLD” on the browser.

How to create Hello World Servlet example using eclipse IDE with Tomcat 7 14