Servlet program using Eclipse IDE.

Hello Friends,

This tutorial is regarding development of Servlet program using Eclipse IDE. Eclipse IDE is very popularly used for development of various web based and java applications. Servlet applications are very easily developed using the eclipse IDE. Following are the simple steps for the same.

Step 1) Open the Eclipse IDE and set the Perspective to Java EE (if not set by default).

Step 2) Create a new Project from File -> New -> Dynamic Web project.

Step3) Enter the details for the project for e.g. Project Name, Target runtime, Configuration etc. For now, we can concentrate on Project Name and target Runtime. Target Runtime is used to set the runtime environment for your servlet programs. In this tutorial we will set up the Apache Tomcat server for running our application.

Step 4) Setting up the Target Runtime: Click the New Runtime button and select the tomcat version you have installed. Then click on Next.

Step 5) Now, browse to the tomcat lib folder path and click on finish. Also finish the Project creation wizard.

Step 6) At this stage the Project is created in eclipse. Now right click on the project and create new Servlet.

Step 7) Enter the details for your servlet file and click finish.

Add below lines in the doGet() function and save it:-

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
    PrintWriter out = response.getWriter();
    out.println("Hello World from code2java");
}

Then Right click on the project or code snippet and click Run As -> Run On Server. The server will start by itself and will run the program for you, if there is no error then the output will be printed.

Check the output 🙂

Hope this will help you. Please write your reviews at admin@code2java.com

Regards,

Nikhil Naoghare.

Related Posts

  • Abstract Class In JAVA

    Hello Friends, This tutorial is for all the Java followers. One of the best feature that is widely used is the term ‘Abstract’. This term can be used as either class or a simple method. An abstract method is any method that is just declared but not instantiated. In other words one can just create…

  • Threads in Java.

    Hello Friends, This is the tutorial for the java developers. One of the most significance feature of core java is Threading. Threading deals with the processing of Threads in a single java program. Let us learn what actually are Threads. *What are Threads? Threads are independently running processes that are isolated from each other upto…

  • Collections In Java.

    Hello friends, Welcome to another tutorial for java followers. You all may have heard about Collections, it is one of the amazing feature in java. Collections are the object for the group of elements, these elements are nothing but the different data structures like as Array Lists, Linked Lists, Vectors, Hash tables,Hash List, Trees, Hash…

  • Maven Installation.

    Hello Friends, This is one of my tutorial for installation of Maven on windows. Maven is a software project management tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information. Maven is an open source community and is a…

  • Jira Plugin Deployment.

    Hello Friends, This is one of the most important tutorial for all the jira developers. You may have heard about the plugins in jira which is a simple Java Archive File with .jar extension. This JAR file contains the class files and auxiliary resources associated with the applications. In Jira we can use Eclipse IDE…

3 Comments

    1. Hi Vishal,
      I guess you have not installed the apache tomcat properly. What kind of error you are getting, please mention that.

      Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.