This tutorial gives step-by-step guide for creating and running a servlet program on windows platform.

  • Step 1: Create an application directory parellel to the ROOT directory under /webapps directory, here “demoApp”. Also create “WEB-INF” folder under recently created application directory and a “classes” folder under “WEB-INF” directory.
  • Step 2: Create a new java file, here “”, and write this code inside this file:

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

public class demoServlet extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
PrintWriter out = res.getWriter();
String myName = req.getParameter(“myname”);
out.println(“<head><title>Hello “+myName+”</title></head>”);
out.println(“Welcome “+myName+”!”);
out.println(“</body> </html>”);

  • Step 3: Create a web.xml file under /WEB-INF directory. Put these configuration under web.xml file:
  • Step 4: Compile the java class created in 2nd step using command prompt (javac from “WEB-INF/classes” folder.
  • Step 5: Browse “http://localhost:8080/newApp/demoServlet?myname=user” from browser. You will see an output, something like this screen-shot:

Here, I have assumed that you have Java Development Kit (JDK) and Apache Tomcat Server installed and configured on your machine.

Leave a Reply

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