Simple Dynamic web Application using Servlet

Steps to create Servlet project in eclipse

  1.  Create the Dynamic web project
  2. Create Servlet in SRC folder
  3.  If you see compilation error then Download servlet.jar file and Copy that file into Webcontent/web-inf/lib Folder
  4. Configure Web URL for Servlet(in web.xml)
  5.  Start web server
  6. Now you can access web Application using web URL.

step 1: Create New Dynamic web project


step 2: Give project name

step 3: Expands Project folder


step 4: Create new package


step 5: Give package name


step 6: Right click on package and create new Servlet


package com.spy.javaforlearn;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FirstServlet extends HttpServlet 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
		         throws ServletException, IOException 
    	PrintWriter out= response.getWriter();
    	out.println("<h1>Welcome to</h2>");


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
 xsi:schemaLocation="" id="WebApp_ID" version="2.5">


  •  Web.xml is known as deployment descriptor for web application.
    It is an instruction sheet for web application.
  • If you have not configured web URL then Default it checks file in
    <welcome-file-list> attribute.
  • To configured Web URL We uses <servlet> and <servlet-mapping> two Attribute.
step 7: Click on run button and select tomcat server to run Servlet


  • How to Configure Web url
    If we create dynamic web project using Module 2.5 then We usually configure web url in web.xml Above dynamic web project we created using module 2.5 so we configured web url in web.xml
  • Note: If we create dynamic web project using Module above 2.5 then We configure web url using annotation
How can we know which servlet is mapped to which url ?

  • <servlet> and <servlet-mapping> both have common attribute called
    <servlet-name> so we can identified through it.
Accessing web app using following web url


1. http (protocol) :

  • Common language which used for communication between web browser
    and web server

2. localhost :

  • it is host name or ip address of pc

3. 8980 :

  • It is port number( It Uniquely identified web Application)

4. FirstServlet :

  • it is project name

5. FirstServlet :

  • Configured web url for Servlet

Leave a Reply

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