MVC stands for Model View Controller. The Spring MVC framework is one of the popular frameworks across all the frameworks available in the market. Because the advantages of Spring MVC framework tells the importance of Spring MVC. In this tutorial we are going develop step by step Spring MVC Helloworld Example using Netbeans.

Spring MVC Helloworld Example:

Step 1: Create a new Project in Netbeans by selecting the new project in File menu and select the web application in the choose project pop-up and click next. Spring MVC I Step 2: Give the project name as you want, For now I am giving SampleSpringApplication. Choose the project location where you want to save the project. By default it is in Netbeans projects in your home directory. Spring MVC II If you want to place all dependencies (libraries) in one folder, you can check the Use Dedicated Folder for Sorting Libraries option. Then click next. Step 3 : Select the application server and J2EE version from the drop-down menu. And select next. Spring MVC III Step 4: Select the Spring Web MVC frame work from Frameworks menu. You can also select the version of the selected framework in libraries tab. If you want to include the JSTL in your application, you can select the JSTL check box. And click finish. Spring MVC IV Step 5 : Yes, we are done. By clicking on the finish button, netbeans will provide us the basic spring application architecture like below. Spring MVC V Step 6: Update the diapatcher-servlet.xml like below.

[sourcecode language="xml"]

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns=""
    <bean class=""/>
    <context:annotation-config />
    <context:component-scan base-package="controllers" />
    <mvc:annotation-driven />

    <bean id="viewResolver"
          p:suffix=".jsp" />


Step 7: Web.xml

[sourcecode language="xml"]

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


Step 8: Create controllers package in Source Package. And Create in controllers package.

[sourcecode language="java"]

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

public class HelloWorldController {

    @RequestMapping(method = RequestMethod.GET)
    public String helloWorld(ModelMap modelMap) {
        System.out.println("on method");
        modelMap.put("printme", "Hello Spring !!");
        return "index";


Step 9: Modify index.jsp like below,

[sourcecode language="html"]

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome to Spring Web MVC project</title>
        <div style="background-color: green;height: 200px;width: 500px">
            <h1 style="color:black;"> ${printme}</h1>


Step 10 : Modify the redirect.jsp like below,

[sourcecode language="java"]

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% response.sendRedirect("helloworld.htm"); %>


Well, it DONE !! To run the application Out put: Spring MVC Helloworld


  1. Huseyin Emre Arikan February 28, 2016 at 2:05 pm - Reply

    Thanks for the note. Two humble remarks for improvement:
    1.A tree view after creating the new files would be helpful, so that everyone knows where exactly in the file directory the new files are to be created.
    2.Not the end state of the default files but what is specifically edited (before and after)? That would I have wanted to know.
    Have a great day!

  2. NAS Kavinda September 8, 2016 at 1:15 pm - Reply

    Thanks for you lot. This is really help to me start learn Spring framework.

  3. Rushikesh February 17, 2017 at 7:02 am - Reply

    Nice article. Very helpful. I am having some doubts regarding the request flow.
    As per my understanding, request flow is as follows (Please correct me if any thing is wrong) :
    1. Request url is containing ‘helloworld.htm’.
    2. Web.xml tell that any request that contain ‘*.htm’ should be sent to servlet named ‘dispatcher-servlet’
    3. Dispatcher servlet has ‘context : component scan’ . using this, spring understands that there must be some controller class for which there is @Controller annotation for it and @Request Mapping annotation is added with value = ‘helloword.htm’. i.e. all requests with such url pattern should be re-directed to this controller.
    4. Request will check for default method with annotation ‘@RequestMapping(method = RequestMethod.GET)’
    5. Response of this method will be returned.

    My doubts:
    1. How it is determined that response of method ‘helloWorld’ will be returned to index.jsp
    2. What if I want to redirect the response from this method to some other jsp file ?
    3. If I am having multiple methods in controller class, and want to call different methods in different situations, how would I manage it ?
    4. Does the sequence of ‘xmlns:context’ and ‘xmlns:mvc’ matters ?

    Thanks In Advance !

  4. silver February 28, 2017 at 3:07 pm - Reply

    Hi I’m getting a Error 404
    No mapping found for HTTP request with URI [/SampleSpringApplication/helloworld.htm] in DispatcherServlet with name ‘dispatcher’

    Did I Do something wrong?

  5. Vikum Samaranayake May 31, 2017 at 4:21 pm - Reply

    Thanks. 😀 Helps a lot. Keep it up

  6. Priya July 25, 2017 at 9:24 am - Reply

    Thanks a lot, please provide simple more examples on this and how configuration file works

  7. Luis Gomez December 18, 2017 at 3:40 pm - Reply

    The only full working tuto. Thanks a lot.

Leave A Comment